Skip to content

Commit fd7e64e

Browse files
committed
Update documentation
1 parent f2116e1 commit fd7e64e

File tree

5 files changed

+110
-14
lines changed

5 files changed

+110
-14
lines changed

docs/core_components.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Edges are the glue that binds tasks together. They define the transitions
3636
between tasks. They are represented by a simple list of tuples. Edges have no
3737
behavior but define the structure of a workflow.
3838

39-
Component API
40-
-------------
39+
Advanced Process API
40+
--------------------
4141

4242
.. autoclass:: galahad.models.Process
4343
:show-inheritance:

docs/tasks.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,117 @@ Tasks
88
Human
99
-----
1010

11+
Human tasks are represented by a Django :class:`View<django.views.generic.base.View>`.
12+
13+
A user can change the processes state via a Django form or a JSON API.
14+
Anything you can do in a view you can do in a human task. They only
15+
difference to machine tasks is that they require some kind of interaction.
16+
17+
You can use view mixins like the
18+
:class:`PermissionRequiredMixin<django.contrib.auth.mixins.PermissionRequiredMixin>`
19+
or
20+
:class:`LoginRequiredMixin<django.contrib.auth.mixins.LoginRequiredMixin>`
21+
to create your own tasks that are only available to certain users.
22+
23+
Generic human tasks
24+
~~~~~~~~~~~~~~~~~~~
25+
1126
.. automodule:: galahad.tasks.human
1227
:members:
1328

1429
Machine
1530
-------
1631

32+
Machine tasks are represented by simple methods on the `Process` class.
33+
34+
They can change the state and perform any action you can think of. They can
35+
decide which task to execute next (exclusive gateway) but also start or wait
36+
for multiple other tasks (split/join gateways).
37+
38+
Furthermore tasks can implement things like sending emails or fetching data
39+
from an 3rd party API. All tasks are executed asynchronously to avoid blocking
40+
IO and locked to prevent raise conditions.
41+
42+
Return values
43+
~~~~~~~~~~~~~
44+
45+
Machine tasks have three different allowed return values all of which will
46+
cause the process to behave differently:
47+
48+
``None``:
49+
If a task returns ``None`` or anything at all the process will just
50+
proceed as planed and follow all outgoing edges and execute the nexttasks.
51+
52+
``Iterable``:
53+
A task can return also an explicit list of tasks that should be executed
54+
next. This can be used to create exclusive gateways::
55+
56+
from django.utils import timezone
57+
from galahad.models import Process
58+
from galahad import tasks
59+
60+
61+
class ExclusiveProcess(Process):
62+
start = tasks.Start()
63+
64+
def is_workday(self):
65+
if timezone.localtime().weekday() < 5:
66+
return [self.work]
67+
else:
68+
return [self.chill]
69+
70+
def work(self):
71+
# pass time at the water cooler
72+
pass
73+
74+
def chill(self):
75+
# enjoy life
76+
pass
77+
78+
edges = (
79+
(start, is_workday),
80+
(is_workday, work),
81+
(is_workday, chill),
82+
)
83+
84+
A task can also return am empty list. This will cause the process branch
85+
to come to a halt and no further stats will be started.
86+
87+
``False``:
88+
A task can also return a boolean. Should a task return ``False`` the
89+
process will wait until the condition changes to ``True`` (or anything but
90+
``False``)::
91+
92+
from galahad.models import Process
93+
from galahad import tasks
94+
from django.utils import timezone
95+
96+
97+
class WaitingProcess(Process):
98+
start = tasks.Start()
99+
100+
def wait_for_weekend(self):
101+
return timezone.now().weekday() >= 5
102+
103+
def go_home(self):
104+
# enjoy life
105+
pass
106+
107+
edges = (
108+
(start, wait_for_weekend),
109+
(wait_for_weekend, go_home),
110+
)
111+
112+
Exceptions
113+
~~~~~~~~~~
114+
115+
Should a task raise an exception the tasks will change it status to failed.
116+
The exception that caused the task to fail will be recorded on the task
117+
itself and further propagated. You can find and rerun failed tasks form
118+
Django's admin interface.
119+
120+
Generic machine tasks
121+
~~~~~~~~~~~~~~~~~~~~~
122+
17123
.. automodule:: galahad.tasks.machine
18124
:members:

galahad/tasks/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
44
A task can be considered as a simple transaction that changes state of a process.
55
There are two types of tasks, human and machine tasks.
6-
7-
Human tasks are represented by a Django :class:`View<django.views.generic.base.View>`.
8-
A user can change the processes state via a Django form or a JSON API.
9-
10-
Machine tasks are represented by simple methods on the `Process` class. They
11-
can change the state and perform any action you can think of. They can decide
12-
which task to execute next (exclusive gateway) but also start or wait for multiple
13-
other tasks (split/join gateways).
14-
15-
Furthermore tasks can implement things like sending emails or fetching data
16-
from an 3rd party API. All tasks are executed asynchronously to avoid blocking
17-
IO and locked to prevent raise conditions.
186
"""
197
from .machine import * # NoQA
208
from .human import * # NoQA

galahad/tasks/human.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Set of reusable human tasks."""
12
from django.views import generic
23

34
from galahad.views import TaskViewMixin

galahad/tasks/machine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Set of reusable machine tasks."""
12
from typing import Iterable
23
from django.utils import timezone
34

0 commit comments

Comments
 (0)