Skip to main content

An easy worker wrapper to create Zeebe Workers

Project description

Zeebe Worker

A simple Zeebe worker wrapper to let developers focus on what matters.

Install

pip install zeebe-worker or use your preferred package manager. See https://pypi.org/project/zeebe-worker/#history for available versions.

Usage

from zeebe_worker import ZeebeWorker
from extensions import zeebe_stub
from config import worker_name

class MyWorker(ZeebeWorker):

    def my_task_type_handler(self, job):
        """Handling my_task_type
        """
        variables = json.loads(job.variables)
        if something_fails:
            # This will trigger a FailJobRequest with the exception
            raise Exception
        return variables

    def another_task_type_handler(self, job):
        """Handles another task
        """
        # This will always succeed as an exception will never be raised
        pass


# Create your own class instance with your own configuration
my_worker = MyWorker(zeebe_stub, worker_name)

# Subscribe to a task type (uses threading.Thread for concurrency)
my_worker.subscribe('my_task_type', 'my_task_type_handler')
my_worker.subscribe('my-task-typo', 'my_task_type_handler')
my_worker.subscribe('another_task_type', 'another_task_type_handler')

API

ZeebeWorker.__init__

Initiates the worker class with the set defaults.

arg desc default
stub The grpc stub to connect to Zeebe with -
worker_name The worker_name te send to along to Zeebe (mainly for debugging purposes) -
timeout The default timeout for a job which is activated by this worker 5*60*1000 (5 minutes)
request_timeout The default timeout for a ActivateJobs request to timeout 1*60*1000 (1 minute)
max_jobs_to_activate The default maximum amount of jobs to activate in one request 1

ZeebeWorker.subscribe

Subscribes the target to the task type concurrently.

arg desc default
task_type The task or job type to subscribe to -
target The function to execute. When using a string, it will convert that to the method within the current class -
timeout The timeout for the jobs which are activated set at class instantiation
request_timeout The timeout for the ActivateJobs request to timeout set at class instantiation
max_jobs_to_activate The maximum amount of jobs to activate in one request set at class instantiation

Target functions

Your own target function must accept one argument, preferably called job. This will be provided as Zeebe's ActivatedJob (ref). Extract the variables using variables = json.loads(job.variables).

Fail a job

Raising any exception in the function will send a FailJobRequest to zeebe with the raised exception.

Complete a job

A CompleteJobRequest will be sent for the job if the function excecutes without raising an exception.

Setting variables

When the function returns a dict, it will send this dict as variables with the CompleteJobRequest.

Compatability

Zeebe Worker Zeebe
0.2.0-beta1 0.22.1
0.1.0 0.22.1

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

zeebe_worker-0.2.0b3.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file zeebe_worker-0.2.0b3.tar.gz.

File metadata

  • Download URL: zeebe_worker-0.2.0b3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.8

File hashes

Hashes for zeebe_worker-0.2.0b3.tar.gz
Algorithm Hash digest
SHA256 aecc0f74495e3fba095b5cd60957e503c4a5d5d30cddf54ad4c0cb3a7f628f38
MD5 f657b96b09b04967280c07f10c004e55
BLAKE2b-256 9f961f1e23ec0d6165bd2701ad914ba007d1c11e6dd2494e5eae27d726a6d276

See more details on using hashes here.

Supported by

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