def __init__(self,
                 parent,
                 name,
                 file,
                 in_assign = None,
                 out_assign = None,
                 **kwargs):
        """
        Constructor.

        @type  parent: TaskSpec
        @param parent: A reference to the parent task spec.
        @type  name: str
        @param name: The name of the task spec.
        @type  file: str
        @param file: The name of a file containing a workflow.
        @type  in_assign: list(str)
        @param in_assign: The names of attributes to carry over.
        @type  out_assign: list(str)
        @param out_assign: The names of attributes to carry back.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        assert file is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.file       = None
        self.in_assign  = in_assign is not None and in_assign or []
        self.out_assign = out_assign is not None and out_assign or []
        if file is not None:
            dirname   = os.path.dirname(parent.file)
            self.file = os.path.join(dirname, file)
Example #2
0
 def __init__(self, parent, **kwargs):
     """
     Constructor.
     
     parent -- a reference to the parent (TaskSpec)
     """
     TaskSpec.__init__(self, parent, 'Start', **kwargs)
Example #3
0
 def __init__(self, parent, name, split_task = None, **kwargs):
     """
     Constructor.
     
     @type  parent: Workflow
     @param parent: A reference to the parent (usually a workflow).
     @type  name: string
     @param name: A name for the task.
     @type  split_task: TaskSpec
     @param split_task: The task that was previously used to split the
                        branch.
     @type  kwargs: dict
     @param kwargs: The following options are supported:
         - threshold: Specifies how many incoming branches need
           to complete before the task triggers.
           When the limit is reached, the task fires but still
           expects all other branches to complete.
           You may also pass an attribute, in which case the
           value is determined at runtime.
         - cancel: When True, any remaining incoming branches
           are cancelled as soon as the discriminator is activated.
           The default is False.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.split_task       = split_task
     self.threshold        = kwargs.get('threshold', None)
     self.cancel_remaining = kwargs.get('cancel',    False)
    def __init__(self,
                 parent,
                 name,
                 file,
                 in_assign=None,
                 out_assign=None,
                 **kwargs):
        """
        Constructor.

        @type  parent: TaskSpec
        @param parent: A reference to the parent task spec.
        @type  name: str
        @param name: The name of the task spec.
        @type  file: str
        @param file: The name of a file containing a workflow.
        @type  in_assign: list(str)
        @param in_assign: The names of attributes to carry over.
        @type  out_assign: list(str)
        @param out_assign: The names of attributes to carry back.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        assert file is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.file = None
        self.in_assign = in_assign is not None and in_assign or []
        self.out_assign = out_assign is not None and out_assign or []
        if file is not None:
            dirname = os.path.dirname(parent.file)
            self.file = os.path.join(dirname, file)
Example #5
0
 def test(self):
     """
     Checks whether all required attributes are set. Throws an exception
     if an error was detected.
     """
     TaskSpec.test(self)
     if len(self.outputs) > 0:
         raise WorkflowException(self, 'CancelJob with an output.')
Example #6
0
 def __init__(self, parent, **kwargs):
     """
     Constructor.
     
     parent -- a reference to the parent (TaskSpec)
     """
     TaskSpec.__init__(self, parent, 'ThreadStart', **kwargs)
     self.internal = True
Example #7
0
 def __init__(self, parent, name, **kwargs):
     """
     Constructor.
     
     parent -- a reference to the parent (TaskSpec)
     name -- a name for the pattern (string)
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.cond_taskspecs = []
     self.choice         = None
Example #8
0
    def __init__(self, parent, name, mutex, **kwargs):
        """
        Constructor.

        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
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.mutex = mutex
Example #9
0
 def __init__(self, parent, name, **kwargs):
     """
     Constructor.
     
     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 tasks to create.
     """
     assert kwargs.has_key('times')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times = kwargs.get('times', None)
Example #10
0
    def __init__(self, parent, name, context, **kwargs):
        """
        Constructor.

        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
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
 def __init__(self, parent, name, **kwargs):
     """
     Constructor.
     
     @type  parent: TaskSpec
     @param parent: A reference to the parent task spec.
     @type  name: str
     @param name: The name of the task spec.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.cond_task_specs = []
     self.choice          = None
Example #12
0
    def __init__(self, parent, name, **kwargs):
        """
        Constructor.

        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
        """
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.cancel_successfully = kwargs.get('success', False)
Example #13
0
 def __init__(self, parent, name, **kwargs):
     """
     Constructor.
     
     @type  parent: TaskSpec
     @param parent: A reference to the parent task spec.
     @type  name: str
     @param name: The name of the task spec.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.cond_task_specs = []
     self.choice = None
Example #14
0
 def test(self):
     """
     Checks whether all required attributes are set. Throws an exception
     if an error was detected.
     """
     TaskSpec.test(self)
     if len(self.cond_taskspecs) < 1:
         raise WorkflowException(self, 'At least one output required.')
     for condition, task in self.cond_taskspecs:
         if task is None:
             raise WorkflowException(self, 'Condition with no task.')
         if condition is None:
             continue
         if condition is None:
             raise WorkflowException(self, 'Condition is None.')
Example #15
0
 def test(self):
     """
     Checks whether all required attributes are set. Throws an exception
     if an error was detected.
     """
     TaskSpec.test(self)
     if len(self.cond_task_specs) < 1:
         raise WorkflowException(self, 'At least one output required.')
     for condition, task in self.cond_task_specs:
         if task is None:
             raise WorkflowException(self, 'Condition with no task.')
         if condition is None:
             continue
         if condition is None:
             raise WorkflowException(self, 'Condition is None.')
Example #16
0
    def __init__(self, parent, name, mutex, **kwargs):
        """
        Constructor.

        :type  parent: TaskSpec
        :param parent: A reference to the parent task spec.
        :type  name: str
        :param name: The name of the task spec.
        :type  mutex: str
        :param mutex: The name of the mutex that should be released.
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert mutex is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.mutex = mutex
Example #17
0
    def __init__(self, parent, name, context, **kwargs):
        """
        Constructor.

        parent -- a reference to the parent (TaskSpec)
        name -- a name for the task (string)
        context -- a list of the names of tasks that are to be triggered
        """
        assert parent  is not None
        assert name    is not None
        assert context is not None
        assert type(context) == type([])
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
        self.times   = kwargs.get('times', 1)
        self.queued  = 0
Example #18
0
 def _on_complete_hook(self, my_task):
     """
     Runs the task. Should not be called directly.
     Returns True if completed, False otherwise.
     """
     my_task._assign_new_thread_id()
     return TaskSpec._on_complete_hook(self, my_task)
Example #19
0
    def __init__(self, parent, name, mutex, **kwargs):
        """
        Constructor.

        :type  parent: TaskSpec
        :param parent: A reference to the parent task spec.
        :type  name: str
        :param name: The name of the task spec.
        :type  mutex: str
        :param mutex: The name of the mutex that should be released.
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert mutex is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.mutex = mutex
Example #20
0
    def __init__(self, parent, name, context, **kwargs):
        """
        Constructor.

        parent -- a reference to the parent (TaskSpec)
        name -- a name for the task (string)
        context -- the name of the MultiChoice that is instructed to
                   select the specified outputs.
        kwargs -- may contain the following keys:
                    choice -- the list of tasks that is selected.
        """
        assert parent is not None
        assert name is not None
        assert context is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
        self.choice = kwargs.get("choice", [])
Example #21
0
 def test(self):
     """
     Checks whether all required attributes are set. Throws an exception
     if an error was detected.
     """
     TaskSpec.test(self)
     if len(self.cond_task_specs) < 1:
         raise WorkflowException(self, 'At least one output required.')
     for condition, name in self.cond_task_specs:
         if name is None:
             raise WorkflowException(self, 'Condition with no task spec.')
         task_spec = self._parent.get_task_spec_from_name(name)
         if task_spec is None:
             msg = 'Condition leads to non-existent task ' + repr(name)
             raise WorkflowException(self, msg)
         if condition is None:
             continue
Example #22
0
    def _on_complete_hook(self, my_task):
        """
        Runs the task. Should not be called directly.
        Returns True if completed, False otherwise.

        my_task -- the task in which this method is executed
        """
        return TaskSpec._on_complete_hook(self, my_task)
Example #23
0
 def __init__(self, parent, name, **kwargs):
     """
     Constructor.
     
     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 my_tasks to create.
                 times-attribute -- the name of the attribute that
                                    specifies the number of outgoing
                                    my_tasks.
     """
     assert kwargs.has_key('times_attribute') or kwargs.has_key('times')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times_attribute = kwargs.get('times_attribute', None)
     self.times           = kwargs.get('times',           None)
     self.thread_starter  = ThreadStart(parent, **kwargs)
     self.outputs.append(self.thread_starter)
     self.thread_starter._connect_notify(self)
Example #24
0
 def _update_state_hook(self, my_task):
     context_task = my_task.job.get_task_from_name(self.context)
     root_task    = my_task.job.task_tree
     for task in root_task._find_any(context_task):
         if task.thread_id != my_task.thread_id:
             continue
         if not task._has_state(Task.COMPLETED):
             my_task._set_state(Task.WAITING)
             return False
     return TaskSpec._update_state_hook(self, my_task)
Example #25
0
    def _on_complete_hook(self, my_task):
        """
        Runs the task. Should not be called directly.
        Returns True if completed, False otherwise.

        my_task -- the task in which this method is executed
        """
        mutex = my_task.job._get_mutex(self.mutex)
        mutex.unlock()
        return TaskSpec._on_complete_hook(self, my_task)
Example #26
0
    def __init__(self, parent, name, **kwargs):
        """
        Constructor.

        parent -- a reference to the parent (TaskSpec)
        name -- a name for the task (string)
        kwargs -- may contain the following keys:
                  file -- name of a file containing a workflow
                  the name of a workflow file
        """
        assert parent  is not None
        assert name    is not None
        assert kwargs.has_key('file')
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.file       = kwargs.get('file',       None)
        self.in_assign  = kwargs.get('in_assign',  [])
        self.out_assign = kwargs.get('out_assign', [])
        if kwargs.has_key('file'):
            dirname   = os.path.dirname(parent.file)
            self.file = os.path.join(dirname, kwargs['file'])
Example #27
0
    def _on_complete_hook(self, my_task):
        """
        Runs the task. Should not be called directly.
        Returns True if completed, False otherwise.

        my_task -- the task in which this method is executed
        """
        for task_name in self.context:
            cancel_tasks = my_task.job.get_task_from_name(task_name)
            for cancel_task in my_task._get_root()._find_any(cancel_tasks):
                cancel_task.cancel()
        return TaskSpec._on_complete_hook(self, my_task)
Example #28
0
    def _on_complete_hook(self, my_task):
        """
        Runs the task. Should not be called directly.
        Returns True if completed, False otherwise.

        my_task -- the task in which this method is executed
        """
        for i in range(self.times + self.queued):
            for task_name in self.context:
                task = my_task.job.get_task_from_name(task_name)
                task._on_trigger(my_task)
        self.queued = 0
        return TaskSpec._on_complete_hook(self, my_task)
Example #29
0
    def _on_complete_hook(self, my_task):
        """
        Runs the task. Should not be called directly.
        Returns True if completed, False otherwise.

        my_task -- the task in which this method is executed
        """
        context = my_task.job.get_task_from_name(self.context)
        for task in my_task.job.task_tree:
            if task.thread_id != my_task.thread_id:
                continue
            if task.spec == context:
                task.trigger(self.choice)
        return TaskSpec._on_complete_hook(self, my_task)
Example #30
0
 def _on_complete_hook(self, my_task):
     mutex = my_task.workflow._get_mutex(self.mutex)
     mutex.unlock()
     TaskSpec._on_complete_hook(self, my_task)
 def test(self):
     TaskSpec.test(self)
     if self.file is not None and not os.path.exists(self.file):
         raise WorkflowException(self,
                                 'File does not exist: %s' % self.file)
Example #32
0
 def test(self):
     TaskSpec.test(self)
     if self.file is not None and not os.path.exists(self.file):
         raise WorkflowException(self, 'File does not exist: %s' % self.file)
Example #33
0
 def _on_complete_hook(self, my_task):
     mutex = my_task.workflow._get_mutex(self.mutex)
     mutex.unlock()
     TaskSpec._on_complete_hook(self, my_task)