Git Product home page Git Product logo

external-task-client's Introduction

Camunda External Taks Client Python

Implement your BPMN Service Task in Python by using the cam.py module. The module cam.py is written in Python3. To use the module Python 3.7 is requiered. This python module was used for the tutorial about external task clients at Camundacon 2019.

Note: This module is a sample and not supported in any way.

Installing

  1. Download the cam.py module from this repo
  2. Put the cam.py module in the same directory, where you want to create your python worker
  3. Create a new python file for the python worker
  4. Import the cam.py module in your python worker python file by using the import statement

Usage

  1. Make sure you have Camunda running.
  2. Create a simple bpmn process model with an External Service Task and define the topic as 'topicName'.
  3. Deploy the process to the Camunda BPM engine.
  4. In your Python code:
import cam

# create a Client instance
camundaTask = cam.client(url = "http://localhost:8080/engine-rest" ) 
"""
arguments for the client:
- 'url': url to the Workflow Engine
- 'workerId': optional argument: unique Name for the external Task client. If not set it provides a default value
"""

# susbscribe to the topic: 'topicName'
camundaTask.subscribe(topic = "topicName")
#Put your business logic for the task here
#complete the task
camundaTask.complete()

Features

This python module features the following: -Extend the lock duration of External Tasks -Report BPMN errors and failures -Share variables with the Workflow Engine

  • Polling tasks from the engine works by performing fetch & lock operation of tasks that have a subscription.
  • If the funcion subscribe from the external task client is used, it will try to fetch and lock task for the registered topic. If no task is available the external task client is polling periodically.
# susbscribe to the topic: 'topicName'
camundaTask.subscribe(topic = "topicName")
"""
Optional arguments:
- 'lockDuration': defines the time the task is locked for the client. Default value: 1000
- 'longPolling' : defines the time a request is suspended if no task is available. Default value: 5000
"""
# susbscribe to the topic: 'topicName'
camundaTask.subscribe(topic = "topicName")

#Put your business logic for the task here

#Create some variables
variables =	{
  "aVariable": "IAmAString",
  "anotherVariable": True,
  "aNumericVariable": 1964
}
#complete the task with variables
camundaTask.complete(**variables)
#Subscribe to the topic 'topicName'
camundaTask.subscribe(topic = "topicName") 

#Put your business logic for the task here

#Handle a Failure
camundaTask.fail(error_message = "some failure message", retries = 0, retryTimeout = 2000)
"""
Optional arguments:
- 'retries': A number of how often the task should be retried. If the number is 0 an incident is created. Default value: 0
- 'retry_timeout' : A timeout in milliseconds before the external task becomes available again for fetching. Default value: 0
"""
#Subscribe to the topic 'topicName'
camundaTask.subscribe(topic = "topicName")

#Put your business logic for the task here

#Create some Variables
variables =	{
  "aVariable": "IAmAString",
  "anotherVariable": True,
  "aNumericVariable": 1964
}
#Handle a BPMN Failure (throw a BPMN error)
camundaTask.error(bpmn_error = "errorCode", "error message", variables)
"""
the bpmn_error code reffers to the error code, that is defined in the BPMN diagram 
Optional arguments:
- 'error_message': An error message that describes the error.
- 'variables' : must be stored in the Python code as dictonary and will be passed to Camunda
"""
#Subscribe to the topic 'topicName'
camundaTask.subscribe(topic = "topicName")

#Put your business logic for the task here

#Extend the lock time
camundaTask.new_lockduration(new_duration ="6000")

external-task-client's People

Contributors

nlea avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.