Ejemplo n.º 1
0
def zeebe_worker(zeebe_adapter):
    worker = ZeebeWorker()
    worker.zeebe_adapter = zeebe_adapter
    return worker
Ejemplo n.º 2
0
from pyzeebe import (Job, ZeebeWorker, create_camunda_cloud_channel,
                     create_insecure_channel, create_secure_channel)
from pyzeebe.errors import BusinessError


# Use decorators to add functionality before and after tasks. These will not fail the task
async def example_logging_task_decorator(job: Job) -> Job:
    print(job)
    return job


# Will use environment variable ZEEBE_ADDRESS or localhost:26500 and NOT use TLS
# create_insecure_channel returns a grpc.aio.Channel instance. If needed you
# can build one on your own
grpc_channel = create_insecure_channel()
worker = ZeebeWorker(grpc_channel)

# With custom hostname/port
grpc_channel = create_insecure_channel(hostname="zeebe-gateway.mydomain",
                                       port=443)
worker = ZeebeWorker(grpc_channel)

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

# With custom hostname/port
grpc_channel = create_secure_channel(hostname="zeebe-gateway.mydomain",
                                     port=443)
worker = ZeebeWorker(grpc_channel)
Ejemplo n.º 3
0
from typing import Dict

from pyzeebe import Job, ZeebeWorker, CamundaCloudCredentials


# Use decorators to add functionality before and after tasks. These will not fail the task
def example_logging_task_decorator(job: Job) -> Job:
    print(job)
    return job


# 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")
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
import os
from typing import Dict
from uuid import uuid4

import pytest

from pyzeebe import ZeebeWorker, ZeebeClient, Job
from pyzeebe.exceptions import WorkflowNotFound

zeebe_client: ZeebeClient
zeebe_worker = ZeebeWorker()


def exception_handler(exc: Exception, job: Job) -> None:
    job.set_error_status(f"Failed to run task {job.type}. Reason: {exc}")


@zeebe_worker.task(task_type="test", exception_handler=exception_handler)
def task_handler(should_throw: bool, input: str) -> Dict:
    if should_throw:
        raise Exception("Error thrown")
    else:
        return {"output": input + str(uuid4())}


@pytest.fixture(scope="module", autouse=True)
def setup():
    global zeebe_client, task_handler

    zeebe_worker.work(watch=True)
def start_worker(event_loop: asyncio.AbstractEventLoop,
                 zeebe_worker: ZeebeWorker):
    event_loop.create_task(zeebe_worker.work())
    yield
    event_loop.create_task(zeebe_worker.stop())
def zeebe_worker(grpc_channel):
    return ZeebeWorker(grpc_channel)
Ejemplo n.º 8
0
def zeebe_worker(aio_grpc_channel: grpc.aio.Channel):
    worker = ZeebeWorker(aio_grpc_channel)
    return worker