Skip to content

Commit

Permalink
Rename Tasks.Task to Tasks.TaskSpec, and add Tasks.Simple.
Browse files Browse the repository at this point in the history
git-svn-id: https://spiff-workflow.googlecode.com/svn/trunk@3 e8300cfb-4550-0410-bd11-c1b1d6e01c17
  • Loading branch information
knipknap committed Jun 24, 2008
1 parent a7e4ffc commit 0dfeb17
Show file tree
Hide file tree
Showing 26 changed files with 129 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/SpiffWorkflow/Job.py
Expand Up @@ -36,7 +36,7 @@ def __init__(self, workflow, **kwargs):
self.outer_job = kwargs.get('parent', self)
self.locks = {}
self.last_node = None
self.task_tree = TaskInstance(self, Tasks.Task(workflow, 'Root'))
self.task_tree = TaskInstance(self, Tasks.Simple(workflow, 'Root'))
self.success = True
self.debug = False

Expand Down
7 changes: 4 additions & 3 deletions src/SpiffWorkflow/Operators/Operator.py
Expand Up @@ -24,12 +24,13 @@ def valueof(scope, op):
return op

class Operator(object):
"""
Abstract base class for all operators.
"""

def __init__(self, *args):
"""
Constructor.
kwargs -- must contain one of left_attribute/left and one of
right_attribute/right.
"""
if len(args) == 0:
raise TypeException("Too few arguments")
Expand Down
2 changes: 1 addition & 1 deletion src/SpiffWorkflow/Server/DB.py
Expand Up @@ -99,7 +99,7 @@ def __update_table_names(self):
})
self.__add_table(table)

# Task table.
# TaskSpec table.
table = Table(pfx + 'task',
self.db_metadata,
Column('id', Integer, primary_key = True),
Expand Down
6 changes: 3 additions & 3 deletions src/SpiffWorkflow/Storage/OpenWfeXmlReader.py
Expand Up @@ -96,7 +96,7 @@ def read_if(self, workflow, start_node):
assert condition is not None
assert match is not None
choice = SpiffWorkflow.Tasks.ExclusiveChoice(workflow, name)
end = SpiffWorkflow.Tasks.Task(workflow, name + '_end')
end = SpiffWorkflow.Tasks.Simple(workflow, name + '_end')
if nomatch is None:
choice.connect(end)
else:
Expand Down Expand Up @@ -181,7 +181,7 @@ def read_task(self, workflow, start_node):
elif type == 'sequence':
return self.read_sequence(workflow, start_node)
elif type == 'task':
task = SpiffWorkflow.Tasks.Task(workflow, name)
task = SpiffWorkflow.Tasks.Simple(workflow, name)
return (task, task)
else:
print "Unknown type:", type
Expand Down Expand Up @@ -212,7 +212,7 @@ def read_workflow(self, start_node):
print "Unknown type:", type
assert False # Unknown tag.

last_task.connect(SpiffWorkflow.Tasks.Task(workflow, 'End'))
last_task.connect(SpiffWorkflow.Tasks.Simple(workflow, 'End'))
return workflow


Expand Down
3 changes: 2 additions & 1 deletion src/SpiffWorkflow/Storage/XmlReader.py
Expand Up @@ -39,6 +39,7 @@ def __init__(self):
module = SpiffWorkflow.Tasks.__dict__[name]
name = re.sub(r'(.)([A-Z])', r'\1-\2', name).lower()
self.task_map[name] = module
self.task_map['task'] = SpiffWorkflow.Tasks.Simple

self.op_map = {'equals': SpiffWorkflow.Operators.Equal,
'not-equals': SpiffWorkflow.Operators.NotEqual,
Expand Down Expand Up @@ -306,7 +307,7 @@ def _read_workflow(self, start_node, filename = None):

# Read all tasks and create a list of successors.
workflow = SpiffWorkflow.Workflow(name, filename)
self.read_tasks = {'end': (SpiffWorkflow.Tasks.Task(workflow, 'End'), [])}
self.read_tasks = {'end': (SpiffWorkflow.Tasks.Simple(workflow, 'End'), [])}
for node in start_node.childNodes:
if node.nodeType != minidom.Node.ELEMENT_NODE:
continue
Expand Down
4 changes: 2 additions & 2 deletions src/SpiffWorkflow/TaskInstance.py
Expand Up @@ -345,11 +345,11 @@ def _is_descendant_of(self, parent):

def _find_child_of(self, parent_task):
"""
Returns the ancestor that has a TaskInstance with the given Task
Returns the ancestor that has a TaskInstance with the given TaskSpec
as a parent.
If no such ancestor was found, the root node is returned.
parent_task -- the wanted parent Task
parent_task -- the wanted parent TaskSpec
"""
if self.parent is None:
return self
Expand Down
10 changes: 5 additions & 5 deletions src/SpiffWorkflow/Tasks/AcquireMutex.py
Expand Up @@ -15,9 +15,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,MA 02110-1301 USA
from SpiffWorkflow.TaskInstance import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from Task import Task
from TaskSpec import TaskSpec

class AcquireMutex(Task):
class AcquireMutex(TaskSpec):
"""
This class implements a task that acquires a mutex (lock), protecting
a section of the workflow from being accessed by other sections.
Expand All @@ -31,12 +31,12 @@ def __init__(self, parent, name, mutex, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the task (string)
mutex -- the mutex that should be acquired
"""
assert mutex is not None
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.mutex = mutex


Expand All @@ -55,4 +55,4 @@ def _on_complete_hook(self, task_instance):
task_instance -- the task_instance in which this method is executed
"""
return Task._on_complete_hook(self, task_instance)
return TaskSpec._on_complete_hook(self, task_instance)
12 changes: 6 additions & 6 deletions src/SpiffWorkflow/Tasks/CancelJob.py
Expand Up @@ -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 Task import Task
from TaskSpec import TaskSpec

class CancelJob(Task):
class CancelJob(TaskSpec):
"""
This class implements a trigger that cancels another task (branch).
If more than one input is connected, the task performs an implicit
Expand All @@ -28,15 +28,15 @@ def __init__(self, parent, name, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the task (string)
kwargs -- may contain the following keys:
lock -- a list of locks that is aquired on entry of
execute() and released on leave of execute().
pre_assign -- a list of attribute name/value pairs
post_assign -- a list of attribute name/value pairs
"""
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.cancel_successfully = kwargs.get('success', False)


Expand All @@ -45,7 +45,7 @@ def test(self):
Checks whether all required attributes are set. Throws an exception
if an error was detected.
"""
Task.test(self)
TaskSpec.test(self)
if len(self.outputs) > 0:
raise WorkflowException(self, 'CancelJob with an output.')

Expand All @@ -58,4 +58,4 @@ def _on_complete_hook(self, instance):
instance -- the instance in which this method is executed
"""
instance.job.cancel(self.cancel_successfully)
return Task._on_complete_hook(self, instance)
return TaskSpec._on_complete_hook(self, instance)
4 changes: 2 additions & 2 deletions src/SpiffWorkflow/Tasks/CancelTask.py
Expand Up @@ -15,7 +15,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from SpiffWorkflow import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from Task import Task
from TaskSpec import TaskSpec
from Trigger import Trigger

class CancelTask(Trigger):
Expand All @@ -38,4 +38,4 @@ def _on_complete_hook(self, instance):
task = instance.job.get_task_from_name(task_name)
for node in instance._get_root()._find_any(task):
node.cancel()
return Task._on_complete_hook(self, instance)
return TaskSpec._on_complete_hook(self, instance)
8 changes: 4 additions & 4 deletions src/SpiffWorkflow/Tasks/Choose.py
Expand Up @@ -15,7 +15,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from SpiffWorkflow import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from Task import Task
from TaskSpec import TaskSpec
from Trigger import Trigger

class Choose(Trigger):
Expand All @@ -32,7 +32,7 @@ def __init__(self, parent, name, context, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the task (string)
context -- the name of the MultiChoice task that is instructed to
select the specified outputs.
Expand All @@ -42,7 +42,7 @@ def __init__(self, parent, name, context, **kwargs):
assert parent is not None
assert name is not None
assert context is not None
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.context = context
self.choice = kwargs.get('choice', [])

Expand All @@ -60,4 +60,4 @@ def _on_complete_hook(self, instance):
continue
if node.task == context:
node.trigger(self.choice)
return Task._on_complete_hook(self, instance)
return TaskSpec._on_complete_hook(self, instance)
2 changes: 1 addition & 1 deletion src/SpiffWorkflow/Tasks/ExclusiveChoice.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, parent, name, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the pattern (string)
"""
MultiChoice.__init__(self, parent, name, **kwargs)
Expand Down
14 changes: 7 additions & 7 deletions src/SpiffWorkflow/Tasks/Gate.py
Expand Up @@ -14,10 +14,10 @@
# 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.TaskInstance import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from Task import Task
from SpiffWorkflow.Exception import WorkflowException
from TaskSpec import TaskSpec

class Gate(Task):
class Gate(TaskSpec):
"""
This class implements a task that can only execute when another
specified task is completed.
Expand All @@ -31,15 +31,15 @@ def __init__(self, parent, name, context, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the task (string)
context -- the name of the task that needs to complete before this
task can execute.
"""
assert parent is not None
assert name is not None
assert context is not None
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.context = context


Expand All @@ -52,7 +52,7 @@ def _update_state_hook(self, instance):
if not node._has_state(TaskInstance.COMPLETED):
instance._set_state(TaskInstance.WAITING)
return False
return Task._update_state_hook(self, instance)
return TaskSpec._update_state_hook(self, instance)


def _on_complete_hook(self, instance):
Expand All @@ -62,4 +62,4 @@ def _on_complete_hook(self, instance):
instance -- the instance in which this method is executed
"""
return Task._on_complete_hook(self, instance)
return TaskSpec._on_complete_hook(self, instance)
10 changes: 5 additions & 5 deletions src/SpiffWorkflow/Tasks/Join.py
Expand Up @@ -16,9 +16,9 @@
from SpiffWorkflow.TaskInstance import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from SpiffWorkflow.Operators import valueof
from Task import Task
from TaskSpec import TaskSpec

class Join(Task):
class Join(TaskSpec):
"""
This class represents a task for synchronizing instances that were
previously split using a conditional task, such as MultiChoice.
Expand All @@ -29,7 +29,7 @@ def __init__(self, parent, name, split_task = None, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the pattern (string)
split_task -- the task that was previously used to split the
instance
Expand All @@ -42,7 +42,7 @@ def __init__(self, parent, name, split_task = None, **kwargs):
cancel -- when set to True, remaining incoming branches
are cancelled as soon as the discriminator is activated.
"""
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.split_task = split_task
self.threshold = kwargs.get('threshold', None)
self.cancel_remaining = kwargs.get('cancel', False)
Expand Down Expand Up @@ -242,4 +242,4 @@ def _on_complete_hook(self, instance):
Runs the task. Should not be called directly.
Returns True if completed, False otherwise.
"""
return Task._on_complete_hook(self, instance)
return TaskSpec._on_complete_hook(self, instance)
10 changes: 5 additions & 5 deletions src/SpiffWorkflow/Tasks/MultiChoice.py
Expand Up @@ -17,9 +17,9 @@
from SpiffWorkflow.Operators import *
from SpiffWorkflow.TaskInstance import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from Task import Task
from TaskSpec import TaskSpec

class MultiChoice(Task):
class MultiChoice(TaskSpec):
"""
This class represents an if condition where multiple conditions may match
at the same time, creating multiple instances.
Expand All @@ -31,10 +31,10 @@ def __init__(self, parent, name, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the pattern (string)
"""
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.cond_tasks = []
self.choice = None

Expand Down Expand Up @@ -64,7 +64,7 @@ def test(self):
Checks whether all required attributes are set. Throws an exception
if an error was detected.
"""
Task.test(self)
TaskSpec.test(self)
if len(self.cond_tasks) < 1:
raise WorkflowException(self, 'At least one output required.')
for condition, task in self.cond_tasks:
Expand Down
8 changes: 4 additions & 4 deletions src/SpiffWorkflow/Tasks/MultiInstance.py
Expand Up @@ -16,9 +16,9 @@
from SpiffWorkflow.TaskInstance import TaskInstance
from SpiffWorkflow.Exception import WorkflowException
from SpiffWorkflow.Operators import valueof
from Task import Task
from TaskSpec import TaskSpec

class MultiInstance(Task):
class MultiInstance(TaskSpec):
"""
When executed, this task performs a split on the current instance.
The number of outgoing instances depends on the runtime value of a
Expand All @@ -33,13 +33,13 @@ def __init__(self, parent, name, **kwargs):
"""
Constructor.
parent -- a reference to the parent (Task)
parent -- a reference to the parent (TaskSpec)
name -- a name for the pattern (string)
kwargs -- must contain one of the following:
times -- the number of instances to create.
"""
assert kwargs.has_key('times')
Task.__init__(self, parent, name, **kwargs)
TaskSpec.__init__(self, parent, name, **kwargs)
self.times = kwargs.get('times', None)


Expand Down

0 comments on commit 0dfeb17

Please sign in to comment.