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:
django.db.models.base.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.
-
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)
-
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)
-
classmethod
-
class
joeflow.models.
Task
(id, _workflow, content_type, name, type, status, completed_by_user, created, modified, completed, exception, stacktrace)[source]¶ Bases:
django.db.models.base.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:
-