Skip to content
Browse files

Remove the Task.TRIGGERED state, add Task.triggered flag instead.

  • Loading branch information...
1 parent f01aeed commit ee8a62073561bca3086a70a077a158cea3579dd1 @knipknap committed
View
21 SpiffWorkflow/Task.py
@@ -66,10 +66,6 @@ class Task(object):
- COMPLETED: The task was regularily completed.
- - TRIGGERED: This is an extra flag that may be used in connection
- with the other states. It means that the task was created at
- runtime, for example by a Trigger or MultiInstance task.
-
Note that the LIKELY and MAYBE tasks are merely predicted/guessed, so
those tasks may be removed from the tree at runtime later. They are
created to allow for visualizing the workflow at a time where
@@ -82,7 +78,6 @@ class Task(object):
READY = 16
CANCELLED = 32
COMPLETED = 64
- TRIGGERED = 128
FINISHED_MASK = CANCELLED | COMPLETED
DEFINITE_MASK = FUTURE | WAITING | READY | FINISHED_MASK
@@ -96,8 +91,7 @@ class Task(object):
CANCELLED: 'CANCELLED',
COMPLETED: 'COMPLETED',
LIKELY: 'LIKELY',
- MAYBE: 'MAYBE',
- TRIGGERED: 'TRIGGERED'}
+ MAYBE: 'MAYBE'}
class Iterator(object):
"""
@@ -173,6 +167,7 @@ def __init__(self, workflow, task_spec, parent=None):
self.parent = parent
self.children = []
self._state = Task.FUTURE
+ self.triggered = False
self.state_history = [Task.FUTURE]
self.log = []
self.task_spec = task_spec
@@ -318,7 +313,7 @@ def _update_children(self, task_specs, state=None):
The state of COMPLETED tasks is never changed.
If this method is passed a state:
- - The state of TRIGGERED tasks is not changed.
+ - The state of triggered tasks is not changed.
- The state for all children is set to the given value.
If this method is not passed a state:
@@ -346,8 +341,8 @@ def _update_children(self, task_specs, state=None):
add = task_specs[:]
remove = []
for child in self.children:
- # Must not be TRIGGERED or COMPLETED.
- if child._has_state(Task.TRIGGERED):
+ # Must not be triggered or COMPLETED.
+ if child.triggered:
if state is None:
child.task_spec._update_state(child)
continue
@@ -485,7 +480,7 @@ def _ready(self):
return
if self.state & self.CANCELLED != 0:
return
- self._set_state(self.READY | (self.state & self.TRIGGERED))
+ self._set_state(self.READY)
return self.task_spec._on_ready(self)
def get_name(self):
@@ -583,7 +578,7 @@ def cancel(self):
for child in self.children:
child.cancel()
return
- self._set_state(self.CANCELLED | (self.state & self.TRIGGERED))
+ self._set_state(self.CANCELLED)
self._drop_children()
return self.task_spec._on_cancel(self)
@@ -592,7 +587,7 @@ def complete(self):
Called by the associated task to let us know that its state
has changed (e.g. from FUTURE to COMPLETED.)
"""
- self._set_state(self.COMPLETED | (self.state & self.TRIGGERED))
+ self._set_state(self.COMPLETED)
return self.task_spec._on_complete(self)
def trigger(self, *args):
View
2 SpiffWorkflow/specs/Join.py
@@ -107,7 +107,7 @@ def _branch_is_complete(self, my_task):
def _branch_may_merge_at(self, task):
for child in task:
# Ignore tasks that were created by a trigger.
- if child._has_state(Task.TRIGGERED):
+ if child.triggered:
continue
# Merge found.
if child.task_spec == self:
View
17 SpiffWorkflow/specs/MultiInstance.py
@@ -45,7 +45,6 @@ def __init__(self, parent, name, times = None, **kwargs):
TaskSpec.__init__(self, parent, name, **kwargs)
self.times = times
-
def _find_my_task(self, task):
for thetask in task.workflow.task_tree:
if thetask.thread_id != task.thread_id:
@@ -54,7 +53,6 @@ def _find_my_task(self, task):
return thetask
return None
-
def _on_trigger(self, task_spec):
"""
May be called after execute() was already completed to create an
@@ -62,13 +60,14 @@ def _on_trigger(self, task_spec):
"""
# Find a Task for this TaskSpec.
my_task = self._find_my_task(task_spec)
+ if my_task._has_state(Task.COMPLETED):
+ state = Task.READY
+ else:
+ state = Task.FUTURE
for output in self.outputs:
- if my_task._has_state(Task.COMPLETED):
- state = Task.READY | Task.TRIGGERED
- else:
- state = Task.FUTURE | Task.TRIGGERED
- output._predict(my_task._add_child(output, state))
-
+ new_task = my_task._add_child(output, state)
+ new_task.triggered = True
+ output._predict(new_task)
def _get_predicted_outputs(self, my_task):
split_n = my_task._get_internal_attribute('splits', 1)
@@ -79,7 +78,6 @@ def _get_predicted_outputs(self, my_task):
outputs += self.outputs
return outputs
-
def _predict_hook(self, my_task):
split_n = valueof(my_task, self.times)
if split_n is None:
@@ -97,7 +95,6 @@ def _predict_hook(self, my_task):
child_state = Task.FUTURE
my_task._update_children(outputs, child_state)
-
def _on_complete_hook(self, my_task):
outputs = self._get_predicted_outputs(my_task)
my_task._update_children(outputs)
View
11 SpiffWorkflow/specs/ThreadSplit.py
@@ -59,7 +59,6 @@ def __init__(self,
self.outputs.append(self.thread_starter)
self.thread_starter._connect_notify(self)
-
def connect(self, task_spec):
"""
Connect the *following* task to this one. In other words, the
@@ -70,7 +69,6 @@ def connect(self, task_spec):
self.thread_starter.outputs.append(task_spec)
task_spec._connect_notify(self.thread_starter)
-
def _find_my_task(self, workflow):
for task in workflow.branch_tree:
if task.thread_id != my_task.thread_id:
@@ -79,7 +77,6 @@ def _find_my_task(self, workflow):
return task
return None
-
def _get_activated_tasks(self, my_task, destination):
"""
Returns the list of tasks that were activated in the previous
@@ -93,7 +90,6 @@ def _get_activated_tasks(self, my_task, destination):
task = destination._find_ancestor(self.thread_starter)
return self.thread_starter._get_activated_tasks(task, destination)
-
def _get_activated_threads(self, my_task):
"""
Returns the list of threads that were activated in the previous
@@ -103,7 +99,6 @@ def _get_activated_threads(self, my_task):
"""
return my_task.children
-
def _on_trigger(self, my_task):
"""
May be called after execute() was already completed to create an
@@ -112,9 +107,8 @@ def _on_trigger(self, my_task):
# Find a Task for this task.
my_task = self._find_my_task(my_task.workflow)
for output in self.outputs:
- state = Task.READY | Task.TRIGGERED
- new_task = my_task.add_child(output, state)
-
+ new_task = my_task.add_child(output, Task.READY)
+ new_task.triggered = True
def _predict_hook(self, my_task):
split_n = my_task.get_attribute('split_n', self.times)
@@ -131,7 +125,6 @@ def _predict_hook(self, my_task):
child_state = Task.LIKELY
my_task._update_children(outputs, child_state)
-
def _on_complete_hook(self, my_task):
# Split, and remember the number of splits in the context data.
split_n = self.times
View
2 SpiffWorkflow/storage/DictionarySerializer.py
@@ -479,6 +479,7 @@ def _serialize_task(self, task, skip_children=False):
# state
s_state['state'] = task.state
+ s_state['triggered'] = task.triggered
# task_spec
s_state['task_spec'] = task.task_spec.name
@@ -511,6 +512,7 @@ def _deserialize_task(self, workflow, s_state):
# state
task._state = s_state['state']
+ task.triggered = s_state['triggered']
# last_state_change
task.last_state_change = s_state['last_state_change']

0 comments on commit ee8a620

Please sign in to comment.
Something went wrong with that request. Please try again.