Skip to main content

Python framework for Cadence Workflow Service

Project description

Intro: Fault-Oblivious Stateful Python Code

cadence-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 services
  • CI/CD pipelines
  • Data pipelines
  • RPA
  • ETL
  • Marketing automation / Customer journeys / Customer engagement
  • Zapier/IFTTT like end user automation.
  • Chat bots
  • Multi-step forms
  • Scheduler/Cron jobs

Behind the scenes, cadence-python uses Cadence as its backend.

For more information about the fault-oblivious programming model refer to the Cadence documentation here

Install Cadencce

wget https://raw.githubusercontent.com/uber/cadence/master/docker/docker-compose.yml
docker-compose up

Register sample domain

docker run --network=host --rm ubercadence/cli:master --do sample domain register -rd 1

Installation cadence-python

pip install cadence-client==1.0.1

Hello World Sample

import sys
import logging
from cadence.activity_method import activity_method
from cadence.workerfactory import WorkerFactory
from cadence.workflow import workflow_method, Workflow, WorkflowClient

logging.basicConfig(level=logging.DEBUG)

TASK_LIST = "HelloActivity-python-tasklist"
DOMAIN = "sample"


# Activities Interface
class GreetingActivities:
    @activity_method(task_list=TASK_LIST, schedule_to_close_timeout_seconds=2)
    def compose_greeting(self, greeting: str, name: str) -> str:
        raise NotImplementedError


# Activities Implementation
class GreetingActivitiesImpl:
    def compose_greeting(self, greeting: str, name: str):
        return f"{greeting} {name}!"


# Workflow Interface
class GreetingWorkflow:
    @workflow_method(execution_start_to_close_timeout_seconds=10, task_list=TASK_LIST)
    async def get_greeting(self, name: str) -> str:
        raise NotImplementedError


# Workflow Implementation
class GreetingWorkflowImpl(GreetingWorkflow):

    def __init__(self):
        self.greeting_activities: GreetingActivities = Workflow.new_activity_stub(GreetingActivities)

    async def get_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.
        return await self.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 / TODO

cadence-python is still under going heavy development. It should be considered EXPERIMENTAL at the moment. A production version is targeted to be released in September of 2019 January 2020 March 2020 April 2020.

1.0

  • Tchannel implementation
  • Python-friendly wrapper around Cadence's Thrift API
  • Author activities in Python
  • Start workflows (synchronously)
  • Create workflows
  • Workflow execution in coroutines
  • Invoke activities from workflows
  • ActivityCompletionClient heartbeat, complete, complete_exceptionally
  • Activity heartbeat, getHeartbeatDetails and doNotCompleteOnReturn
  • Activity retry
  • Activity getDomain(), getTaskToken(), getWorkflowExecution()
  • Signals
  • Queries
  • Async workflow execution
  • await
  • now (currentTimeMillis)
  • Sleep
  • Loggers
  • newRandom
  • UUID
  • Workflow Versioning
  • WorkflowClient.newWorkflowStub(Class workflowInterface, String workflowId);

1.1

  • ActivityStub and Workflow.newUntypedActivityStub
  • Classes as arguments and return values to/from activity and workflow methods
  • WorkflowStub and WorkflowClient.newUntypedWorkflowStub
  • Custom workflow ids through start() and new_workflow_stub()
  • ContinueAsNew
  • Compatibility with Java client
  • Compatibility with Golang client

2.0

  • Sticky workflows

Post 2.0:

  • sideEffect/mutableSideEffect
  • Local activity
  • Parallel activity execution
  • Timers
  • Cancellation Scopes
  • Child Workflows
  • Explicit activity ids for activity invocations

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cadence-client-1.0.1.tar.gz (53.9 kB view details)

Uploaded Source

Built Distribution

cadence_client-1.0.1-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

File details

Details for the file cadence-client-1.0.1.tar.gz.

File metadata

  • Download URL: cadence-client-1.0.1.tar.gz
  • Upload date:
  • Size: 53.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for cadence-client-1.0.1.tar.gz
Algorithm Hash digest
SHA256 77a1ba8f0c21a900e29fe5e8079adfff6991633465cf9f822e163d1f15dba795
MD5 85338882bf70fd191472cd818c3dee42
BLAKE2b-256 c223eb6d6275cf13c37f5284b4618bf42c18cd0d8370655e3b23dda330a8228c

See more details on using hashes here.

File details

Details for the file cadence_client-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: cadence_client-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 60.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for cadence_client-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 294989f48e7e868c6ca5b4bea5290b8bee05e864e365e82c9c783b72d634ebaf
MD5 9b2f9b7dac660e03461f8e99564c7188
BLAKE2b-256 b9a0b32de069f03b942783fae8051083d2799bac0d0aba38c31e465935d1bef8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page