Core Components

Workflow

The Workflow is where all your components come together. It defines the flow overall flow and the different states of your workflow. Workflow are also the vehicle for the other two components Tasks and edges.

It combines both behavior and state using familiar components. The state is persisted via a Django Model for each instance of your workflow.

Task

A task defines the behavior of a workflow. It can be considered as a simple transaction that changes state of a workflow. There are two types of tasks, human and machine tasks.

Human tasks are represented by a Django View. A user can change the workflows state via a Django form or a JSON API.

Machine tasks are represented by simple methods on the Workflow class. They can change the state and perform any action you can think of. They can decide which task to execute next (exclusive gateway) but also start or wait for multiple other tasks (split/join gateways).

Furthermore tasks can implement things like sending emails or fetching data from an 3rd party API. All tasks are executed asynchronously to avoid blocking IO and locked to prevent raise conditions.

Edges

Edges are the glue that binds tasks together. They define the transitions between tasks. They are represented by a simple list of tuples. Edges have no behavior but define the structure of a workflow.

Advanced Workflow API

class joeflow.models.Workflow(*args, **kwargs)[source]

Bases: Model

The WorkflowState object holds the state of a workflow instances.

It is represented by a Django Model. This way all workflow states are persisted in your database.

get_absolute_url()[source]

Return URL to workflow detail view.

classmethod get_graph_svg()[source]

Return graph representation of a model workflow as SVG.

The SVG is HTML safe and can be included in a template, e.g.:

<html>
<body>
<!--// other content //-->
{{ workflow_class.get_graph_svg }}
<!--// other content //-->
</body>
</html>
Returns:

SVG representation of a running workflow.

Return type:

(django.utils.safestring.SafeString)

get_instance_graph_svg(output_format='svg')[source]

Return graph representation of a running workflow as SVG.

The SVG is HTML safe and can be included in a template, e.g.:

<html>
<body>
<!--// other content //-->
{{ object.get_instance_graph_svg }}
<!--// other content //-->
</body>
</html>
Returns:

SVG representation of a running workflow.

Return type:

(django.utils.safestring.SafeString)

get_override_url()[source]

Return URL to workflow override view.

rankdir = 'LR'[source]

Direction of the workflow’s graph visualization.

classmethod urls()[source]

Return all URLs to workflow related task and other special views.

Example:

from django.urls import path, include

from . import models

urlpatterns = [
    # …
    path('myworkflow/', include(models.MyWorkflow.urls())),
]
Returns:

Tuple containing aw list of URLs and the workflow namespace.

Return type:

tuple(list, str)

class joeflow.models.Task(id, _workflow, content_type, name, type, status, completed_by_user, created, modified, completed, exception, stacktrace)[source]

Bases: Model

enqueue(countdown=None, eta=None)[source]

Schedule the tasks for execution.

Parameters:
  • countdown (int) – Time in seconds until the time should be started.

  • eta (datetime.datetime) – Time at which the task should be started.

Returns:

Celery task result.

Return type:

celery.result.AsyncResult

start_next_tasks(next_nodes: list = None)[source]

Start new tasks following another tasks.

Parameters:
  • self (Task) – The task that precedes the next tasks.

  • next_nodes (list) – List of nodes that should be executed next. This argument is optional. If no nodes are provided it will default to all possible edges.