Skip to content

Generate inbound template

We can create a template for SleepConnector using

$ generate_template example.SleepConnector example/sleep.json
Generated template for example.SleepConnector

Tip

For more info on template generation see Generate outbound template.

Template conversion

SleepConnector class have been converted to a template:

  • name of the template was picked up from ConnectorConfig.name
  • zeebe:taskDefinition:type was set to ConnectorConfig.type (not visible in Modeler).
  • duration field of the SleepConnector was converted into a zeebe:input property.
  • A zeebe:taskHeader with key 'resultVariable' was added to allow users define the name of the variable where the output of the LogConnector.run method will be stored.
  • A 'Message name' and 'Correlation key' inputs were added.

Template

example/sleep.json
{
  "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.9.0/resources/schema.json",
  "name": "Sleep",
  "id": "a631e9a0-939e-4d73-b78c-34939e44eab0",
  "appliesTo": [
    "bpmn:ServiceTask"
  ],
  "properties": [
    {
      "binding": {
        "type": "zeebe:input",
        "name": "duration"
      },
      "label": "Duration of sleep in seconds",
      "type": "String",
      "group": "input",
      "feel": "optional"
    },
    {
      "binding": {
        "type": "zeebe:taskHeader",
        "key": "resultVariable"
      },
      "label": "Result variable",
      "type": "String",
      "group": "output"
    },
    {
      "binding": {
        "type": "zeebe:taskDefinition:type"
      },
      "type": "Hidden",
      "value": "sleep"
    },
    {
      "binding": {
        "type": "zeebe:input",
        "name": "correlation_key"
      },
      "label": "Correlation key",
      "type": "String",
      "group": "config",
      "feel": "optional"
    },
    {
      "binding": {
        "type": "zeebe:input",
        "name": "message_name"
      },
      "label": "Message name",
      "type": "String",
      "group": "config",
      "feel": "optional"
    }
  ],
  "groups": [
    {
      "id": "input",
      "label": "Input"
    },
    {
      "id": "output",
      "label": "Output"
    },
    {
      "id": "config",
      "label": "Configuration"
    }
  ]
}
example/sleep.py
import asyncio

from pydantic import Field

from python_camunda_sdk import InboundConnector


class SleepConnector(InboundConnector):
    duration: int = Field(description="Duration of sleep in seconds")

    async def run(self) -> bool:
        await asyncio.sleep(self.duration)
        return True

    class ConnectorConfig:
        name = "Sleep"
        type = 'sleep'