def test_overrides_default_hostname_if_provided(
            self, insecure_channel_mock: Mock):
        hostname = str(uuid4())

        create_insecure_channel(hostname=hostname)

        insecure_channel_call = insecure_channel_mock.mock_calls[0]
        assert insecure_channel_call.args[0] == f"{hostname}:{DEFAULT_PORT}"
    def test_overrides_default_port_if_provided(self,
                                                insecure_channel_mock: Mock):
        port = 123

        create_insecure_channel(port=port)

        insecure_channel_call = insecure_channel_mock.mock_calls[0]
        assert insecure_channel_call.args[0] == f"{DEFAULT_HOSTNAME}:{port}"
    def test_uses_default_address(self, insecure_channel_mock: Mock):
        create_insecure_channel()

        insecure_channel_call = insecure_channel_mock.mock_calls[0]
        assert insecure_channel_call.args[0] == create_address()
    def test_calls_using_default_grpc_options(self,
                                              insecure_channel_mock: Mock):
        create_insecure_channel()

        insecure_channel_call = insecure_channel_mock.mock_calls[0]
        assert insecure_channel_call.kwargs["options"] == get_channel_options()
    def test_returns_aio_grpc_channel(self):
        channel = create_insecure_channel()

        assert isinstance(channel, grpc.aio.Channel)
Example #6
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)
Example #7
0
from pyzeebe import (ZeebeClient, create_camunda_cloud_channel,
                     create_insecure_channel, create_secure_channel)

# Create a zeebe client without credentials
grpc_channel = create_insecure_channel(hostname="localhost", port=26500)
zeebe_client = ZeebeClient(grpc_channel)

# Create a zeebe client with TLS
grpc_channel = create_secure_channel()
zeebe_client = ZeebeClient(grpc_channel)

# Create a zeebe client for camunda cloud
grpc_channel = create_camunda_cloud_channel(
    client_id="<my_client_id>",
    client_secret="<my_client_secret>",
    cluster_id="<my_cluster_id>",
    region="<region>" # Default is bru-2
)
zeebe_client = ZeebeClient(grpc_channel)

# Run a Zeebe instance process
process_instance_key = await zeebe_client.run_process(
    bpmn_process_id="My zeebe process", variables={}
)

# Run a Zeebe process instance and receive the result
process_instance_key, process_result = await zeebe_client.run_process_with_result(
    bpmn_process_id="My zeebe process", timeout=10000
)  # Will wait 10000 milliseconds (10 seconds)

# Deploy a bpmn process definition
def grpc_channel():
    return create_insecure_channel()