Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add serialize() and deserialize() methods for all TaskSpec methods.

  • Loading branch information...
commit b1bc5c53b6950e6604fe2c491e484bfd9a4f2f0d 1 parent 0abf54c
@knipknap authored
View
7 src/SpiffWorkflow/specs/AcquireMutex.py
@@ -50,3 +50,10 @@ def _update_state_hook(self, my_task):
return True
my_task._set_state(Task.WAITING)
return False
+
+ def serialize(self, serializer):
+ return serializer._serialize_acquire_mutex(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_acquire_mutex(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/Cancel.py
@@ -53,3 +53,10 @@ def test(self):
def _on_complete_hook(self, my_task):
my_task.workflow.cancel(self.cancel_successfully)
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_cancel(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_cancel(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/CancelTask.py
@@ -32,3 +32,10 @@ def _on_complete_hook(self, my_task):
for cancel_task in my_task._get_root()._find_any(cancel_tasks):
cancel_task.cancel()
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_cancel_task(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_cancel_task(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/Choose.py
@@ -60,3 +60,10 @@ def _on_complete_hook(self, my_task):
if task.task_spec == context:
task.trigger(self.choice)
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_choose(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_choose(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/ExclusiveChoice.py
@@ -79,3 +79,10 @@ def _on_complete_hook(self, my_task):
my_task._update_children(output)
return True
+
+ def serialize(self, serializer):
+ return serializer._serialize_exclusive_choice(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_exclusive_choice(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/Gate.py
@@ -62,3 +62,10 @@ def _update_state_hook(self, my_task):
def _on_complete_hook(self, my_task):
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_gate(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_gate(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/Join.py
@@ -253,3 +253,10 @@ def _update_state_hook(self, my_task):
def _on_complete_hook(self, my_task):
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_join(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_join(wf_spec, s_state)
View
13 src/SpiffWorkflow/specs/MultiChoice.py
@@ -14,9 +14,9 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import re
-from SpiffWorkflow.Task import Task
+from SpiffWorkflow.Task import Task
from SpiffWorkflow.exceptions import WorkflowException
-from TaskSpec import TaskSpec
+from TaskSpec import TaskSpec
class MultiChoice(TaskSpec):
"""
@@ -85,11 +85,9 @@ def _on_trigger(self, my_task, choice):
"""
self.choice = choice
-
def _predict_hook(self, my_task):
my_task._update_children(self.outputs, Task.MAYBE)
-
def _on_complete_hook(self, my_task):
"""
Runs the task. Should not be called directly.
@@ -106,3 +104,10 @@ def _on_complete_hook(self, my_task):
my_task._update_children(outputs)
return True
+
+ def serialize(self, serializer):
+ return serializer._serialize_multi_choice(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_multi_choice(wf_spec, s_state)
View
12 src/SpiffWorkflow/specs/MultiInstance.py
@@ -29,7 +29,7 @@ class MultiInstance(TaskSpec):
This task has one or more inputs and may have any number of outputs.
"""
- def __init__(self, parent, name, **kwargs):
+ def __init__(self, parent, name, times = None, **kwargs):
"""
Constructor.
@@ -42,9 +42,8 @@ def __init__(self, parent, name, **kwargs):
@type kwargs: dict
@param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
"""
- assert kwargs.has_key('times')
TaskSpec.__init__(self, parent, name, **kwargs)
- self.times = kwargs.get('times', None)
+ self.times = times
def _find_my_task(self, task):
@@ -103,3 +102,10 @@ def _on_complete_hook(self, my_task):
outputs = self._get_predicted_outputs(my_task)
my_task._update_children(outputs)
return True
+
+ def serialize(self, serializer):
+ return serializer._serialize_multi_instance(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_multi_instance(wf_spec, s_state)
View
12 src/SpiffWorkflow/specs/ReleaseMutex.py
@@ -13,9 +13,9 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from SpiffWorkflow import Task
+from SpiffWorkflow import Task
from SpiffWorkflow.exceptions import WorkflowException
-from TaskSpec import TaskSpec
+from TaskSpec import TaskSpec
class ReleaseMutex(TaskSpec):
"""
@@ -44,8 +44,14 @@ def __init__(self, parent, name, mutex, **kwargs):
TaskSpec.__init__(self, parent, name, **kwargs)
self.mutex = mutex
-
def _on_complete_hook(self, my_task):
mutex = my_task.workflow._get_mutex(self.mutex)
mutex.unlock()
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_release_mutex(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_release_mutex(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/Simple.py
@@ -24,4 +24,9 @@ class Simple(TaskSpec):
If more than one output is connected, the task performs an implicit
parallel split.
"""
- pass # Inherit everything from TaskSpec
+ def serialize(self, serializer):
+ return serializer._serialize_simple(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_simple(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/StartTask.py
@@ -60,3 +60,10 @@ def test(self):
raise WorkflowException(self, 'StartTask with an input.')
elif len(self.outputs) < 1:
raise WorkflowException(self, 'No output task connected.')
+
+ def serialize(self, serializer):
+ return serializer._serialize_start_task(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_start_task(wf_spec, s_state)
View
7 src/SpiffWorkflow/specs/SubWorkflow.py
@@ -139,3 +139,10 @@ def _on_complete_hook(self, my_task):
continue
child.task_spec._update_state(child)
return True
+
+ def serialize(self, serializer):
+ return serializer._serialize_sub_workflow(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_sub_workflow(wf_spec, s_state)
View
15 src/SpiffWorkflow/specs/TaskSpec.py
@@ -375,3 +375,18 @@ def _on_complete_hook(self, my_task):
# If we have more than one output, implicitly split.
my_task._update_children(self.outputs)
return True
+
+ def serialize(self, serializer):
+ """
+ Serializes the instance using the provided serializer.
+
+ @type serializer: L{SpiffWorkflow.storage.Serializer}
+ @param serializer: The serializer to use.
+ @rtype: object
+ @return: The serialized object.
+ """
+ return serializer._serialize_task_spec(self)
+
+ @classmethod
+ def deserialize(self, serializer, wf_spec, s_state):
+ return serializer._deserialize_task_spec(wf_spec, s_state)
View
3  src/SpiffWorkflow/specs/ThreadMerge.py
@@ -130,3 +130,6 @@ def _update_state_hook(self, my_task):
def _on_complete_hook(self, my_task):
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_thread_merge(self)
View
3  src/SpiffWorkflow/specs/ThreadSplit.py
@@ -144,3 +144,6 @@ def _on_complete_hook(self, my_task):
outputs.append(self.thread_starter)
my_task._update_children(outputs)
return True
+
+ def serialize(self, serializer):
+ return serializer._serialize_thread_split(self)
View
3  src/SpiffWorkflow/specs/ThreadStart.py
@@ -43,3 +43,6 @@ def __init__(self, parent, **kwargs):
def _on_complete_hook(self, my_task):
my_task._assign_new_thread_id()
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_thread_start(self)
View
11 src/SpiffWorkflow/specs/Trigger.py
@@ -27,7 +27,7 @@ class Trigger(TaskSpec):
parallel split.
"""
- def __init__(self, parent, name, context, **kwargs):
+ def __init__(self, parent, name, context, times = 1, **kwargs):
"""
Constructor.
@@ -35,8 +35,10 @@ def __init__(self, parent, name, context, **kwargs):
@param parent: A reference to the parent task spec.
@type name: str
@param name: The name of the task spec.
- @type context: str
+ @type context: list(str)
@param context: A list of the names of tasks that are to be triggered.
+ @type times: int or None
+ @param times: The number of signals before the trigger fires.
@type kwargs: dict
@param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
"""
@@ -46,7 +48,7 @@ def __init__(self, parent, name, context, **kwargs):
assert type(context) == type([])
TaskSpec.__init__(self, parent, name, **kwargs)
self.context = context
- self.times = kwargs.get('times', 1)
+ self.times = times
self.queued = 0
@@ -81,3 +83,6 @@ def _on_complete_hook(self, my_task):
task._on_trigger(my_task)
self.queued = 0
return TaskSpec._on_complete_hook(self, my_task)
+
+ def serialize(self, serializer):
+ return serializer._serialize_trigger(self)
View
11 src/SpiffWorkflow/specs/WorkflowSpec.py
@@ -50,6 +50,17 @@ def get_task_spec_from_name(self, name):
"""
return self.task_specs[name]
+ def serialize(self, serializer):
+ """
+ Serializes the instance using the provided serializer.
+
+ @type serializer: L{SpiffWorkflow.storage.Serializer}
+ @param serializer: The serializer to use.
+ @rtype: object
+ @return: The serialized object.
+ """
+ return serializer.serialize_workflow_spec(self)
+
@classmethod
def deserialize(cls, serializer, s_state, **kwargs):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.