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 to send to along to Zeebe (mainly for debugging purposes) | - |
| timeout | Number of milliseconds for a job to timeout | 5*60*1000 (5 minutes) |
| request_timeout | Long polling: number of milliseconds for an ActivateJobs request to timeout | 1*60*1000 (1 minute) |
| max_jobs_to_activate | Maximum amount of jobs to activate in one request | 1 |
| backoff_interval | Number of milliseconds to backoff when unable to reach Zeebe | 5*1000 (5 seconds) |
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 | Number of milliseconds for the jobs which are activated to timeout | set at class instantiation |
| request_timeout | Number of milliseconds for the ActivateJobs request to timeout | set at class instantiation |
| max_jobs_to_activate | Maximum amount of jobs to activate in one request | set at class instantiation |
| autocomplete | Complete jobs when the handler returns a non-error | False |
| backoff_interval | Number of milliseconds to backoff when unable to reach Zeebe | 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.x | >= 0.23 |
| 0.1.0 | 0.22.1 |
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file zeebe_worker-0.2.4.tar.gz.
File metadata
- Download URL: zeebe_worker-0.2.4.tar.gz
- Upload date:
- Size: 4.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7d310646030cbe6f0d417593bd54789dbc9661124cd596bdb6fdb8f0ca763d3
|
|
| MD5 |
4d5c2998ad9180ad4b9a73c022e9f862
|
|
| BLAKE2b-256 |
5f1dc7bd070c6b0f8d98604d6c8a9685de8ccea52d3110827df5b33d4059f5ee
|