Esempio n. 1
0
# Will use environment variable ZEEBE_ADDRESS or localhost:26500 and NOT use TLS
worker = ZeebeWorker()

# Will use environment variable ZEEBE_ADDRESS or localhost:26500 and use TLS
worker = ZeebeWorker(secure_connection=True)

# Connect to zeebe cluster in camunda cloud
camunda_cloud_credentials = CamundaCloudCredentials(
    client_id="<my_client_id>",
    client_secret="<my_client_secret>",
    cluster_id="<my_cluster_id>")
worker = ZeebeWorker(credentials=camunda_cloud_credentials)

# Decorators allow us to add functionality before and after each job
worker.before(example_logging_task_decorator)
worker.after(example_logging_task_decorator)


# Create a task like this:
@worker.task(task_type="test")
def example_task() -> Dict:
    return {"output": f"Hello world, test!"}


# Create a task that will return a single value (not a dict) like this:
@worker.task(task_type="add_one", single_value=True,
             variable_name="y")  # This task will return to zeebe: { y: x + 1 }
def add_one(x) -> int:
    return x + 1

Esempio n. 2
0
from loguru import logger
from pyzeebe import ZeebeWorker

from worker.decorators.log_decorator import log_decorator
from worker.tasks import example_task_router
from worker.utils.config import get_credentials, get_zeebe_config

logger.add(sys.stderr,
           format="{time} {level} {message}",
           filter="root",
           level="INFO")

config = ConfigParser()
config.read(os.getenv("CONFIG_FILE_LOCATION") or "/src/config/worker.ini")

credentials = get_credentials(config)
zeebe_config = get_zeebe_config(config)

zeebe_worker = ZeebeWorker(credentials=credentials, **zeebe_config)

zeebe_worker.before(log_decorator)
zeebe_worker.after(log_decorator)

zeebe_worker.include_router(example_task_router)

if __name__ == '__main__':
    logger.info(
        f"Connecting to gateway at address: {zeebe_worker.zeebe_adapter.connection_uri}"
    )
    zeebe_worker.work()