Package: cadence-client
Intro: Fault-Oblivious Stateful Python Codecadence-python allows you to create Python functions that have their state (local variables etc..) implicitly saved such that if the process/machine fails the state of the function is not lost and can resume from where it left off.This programming model is useful whenever you need to ensure that a function runs to completion. For example:Business logic involving multiple micro servicesCI/CD pipelinesData pipelinesRPAETLMarketing automation / Customer journeys / Customer engagementZapier/IFTTT like end user automation.Chat botsMulti-step formsScheduler/Cron jobsBehind the scenes, cadence-python usesCadenceas its backend.For more information about the fault-oblivious programming model refer to the Cadence documentationhereInstall Cadenccewget https://raw.githubusercontent.com/uber/cadence/master/docker/docker-compose.yml
docker-compose upRegistersampledomaindocker run --network=host --rm ubercadence/cli:master --do sample domain register -rd 1Installation cadence-pythonpip install cadence-client==1.0.1Hello World Sampleimportsysimportloggingfromcadence.activity_methodimportactivity_methodfromcadence.workerfactoryimportWorkerFactoryfromcadence.workflowimportworkflow_method,Workflow,WorkflowClientlogging.basicConfig(level=logging.DEBUG)TASK_LIST="HelloActivity-python-tasklist"DOMAIN="sample"# Activities InterfaceclassGreetingActivities:@activity_method(task_list=TASK_LIST,schedule_to_close_timeout_seconds=2)defcompose_greeting(self,greeting:str,name:str)->str:raiseNotImplementedError# Activities ImplementationclassGreetingActivitiesImpl:defcompose_greeting(self,greeting:str,name:str):returnf"{greeting}{name}!"# Workflow InterfaceclassGreetingWorkflow:@workflow_method(execution_start_to_close_timeout_seconds=10,task_list=TASK_LIST)asyncdefget_greeting(self,name:str)->str:raiseNotImplementedError# Workflow ImplementationclassGreetingWorkflowImpl(GreetingWorkflow):def__init__(self):self.greeting_activities:GreetingActivities=Workflow.new_activity_stub(GreetingActivities)asyncdefget_greeting(self,name):# Place any Python code here that you want to ensure is executed to completion.# Note: code in workflow functions must be deterministic so that the same code paths# are ran during replay.returnawaitself.greeting_activities.compose_greeting("Hello",name)if__name__=='__main__':factory=WorkerFactory("localhost",7933,DOMAIN)worker=factory.new_worker(TASK_LIST)worker.register_activities_implementation(GreetingActivitiesImpl(),"GreetingActivities")worker.register_workflow_implementation_type(GreetingWorkflowImpl)factory.start()client=WorkflowClient.new_client(domain=DOMAIN)greeting_workflow:GreetingWorkflow=client.new_workflow_stub(GreetingWorkflow)result=greeting_workflow.get_greeting("Python")print(result)print("Stopping workers....")worker.stop()print("Workers stopped...")sys.exit(0)Status / TODOcadence-python is still under going heavy development. It should be considered EXPERIMENTAL at the moment. A production
version is targeted to be released inSeptember of 2019January 2020March 2020April 2020.1.0Tchannel implementationPython-friendly wrapper around Cadence's Thrift APIAuthor activities in PythonStart workflows (synchronously)Create workflowsWorkflow execution in coroutinesInvoke activities from workflowsActivityCompletionClient heartbeat, complete, complete_exceptionallyActivity heartbeat, getHeartbeatDetails and doNotCompleteOnReturnActivity retryActivity getDomain(), getTaskToken(), getWorkflowExecution()SignalsQueriesAsync workflow executionawaitnow (currentTimeMillis)SleepLoggersnewRandomUUIDWorkflow VersioningWorkflowClient.newWorkflowStub(Class workflowInterface, String workflowId);1.1ActivityStub and Workflow.newUntypedActivityStubClasses as arguments and return values to/from activity and workflow methodsWorkflowStub and WorkflowClient.newUntypedWorkflowStubCustom workflow ids through start() and new_workflow_stub()ContinueAsNewCompatibility with Java clientCompatibility with Golang client2.0Sticky workflowsPost 2.0:sideEffect/mutableSideEffectLocal activityParallel activity executionTimersCancellation ScopesChild WorkflowsExplicit activity ids for activity invocations