Example #1
0
 def __init__(self,
              parent,
              name,
              split_task=None,
              threshold=None,
              cancel=False,
              **kwargs):
     """
     Constructor.
     
     @type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
     @param parent: A reference to the parent (usually a workflow).
     @type  name: string
     @param name: A name for the task.
     @type  split_task: str or None
     @param split_task: The name of the task spec that was previously
                        used to split the branch. If this is None,
                        the most recent branch split is merged.
     @type  threshold: int or L{SpiffWorkflow.operators.Attrib}
     @param 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 resolved at runtime.
     @type  cancel: bool
     @param cancel: When True, any remaining incoming branches are
                    cancelled as soon as the discriminator is activated.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.split_task = split_task
     self.threshold = threshold
     self.cancel_remaining = cancel
Example #2
0
    def __init__(self,
                 parent,
                 name,
                 split_task=None,
                 threshold=None,
                 cancel=False,
                 **kwargs):
        """
        Constructor.

        @type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
        @param parent: A reference to the parent (usually a workflow).
        @type  name: string
        @param name: A name for the task.
        @type  split_task: str or None
        @param split_task: The name of the task spec that was previously
                           used to split the branch. If this is None,
                           the most recent branch split is merged.
        @type  threshold: int or L{SpiffWorkflow.operators.Attrib}
        @param 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 resolved at runtime.
        @type  cancel: bool
        @param cancel: When True, any remaining incoming branches are
                       cancelled as soon as the discriminator is activated.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.split_task = split_task
        self.threshold = threshold
        self.cancel_remaining = cancel
Example #3
0
    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)
 def __init__(self,
              parent,
              name,
              times = None,
              times_attribute = None,
              **kwargs):
     """
     Constructor.
     
     @type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
     @param parent: A reference to the parent (usually a workflow).
     @type  name: string
     @param name: A name for the task.
     @type  times: int or None
     @param times: The number of tasks to create.
     @type  times_attribute: str or None
     @param times_attribute: The name of an attribute that specifies
                             the number of outgoing tasks.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     if not times_attribute and not times:
         raise ValueError('require times or times_attribute argument')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times_attribute = times_attribute
     self.times           = times
     self.thread_starter  = ThreadStart(parent, **kwargs)
     self.outputs.append(self.thread_starter)
     self.thread_starter._connect_notify(self)
Example #5
0
 def __init__(self,
              parent,
              name,
              times=None,
              times_attribute=None,
              **kwargs):
     """
     Constructor.
     
     :type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
     :param parent: A reference to the parent (usually a workflow).
     :type  name: string
     :param name: A name for the task.
     :type  times: int or None
     :param times: The number of tasks to create.
     :type  times_attribute: str or None
     :param times_attribute: The name of an attribute that specifies
                             the number of outgoing tasks.
     :type  kwargs: dict
     :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     if not times_attribute and not times:
         raise ValueError('require times or times_attribute argument')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times_attribute = times_attribute
     self.times = times
     self.thread_starter = ThreadStart(parent, **kwargs)
     self.outputs.append(self.thread_starter)
     self.thread_starter._connect_notify(self)
Example #6
0
    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 #7
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, 'Cancel with an output.')
Example #8
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, "Cancel with an output.")
Example #9
0
    def __init__(self,
                 parent,
                 name,
                 call=None,
                 call_args=None,
                 call_queue=None,
                 call_server_id=None,
                 call_result_key=None,
                 merge_results=True,
                 **kwargs):
        """Constructor.

        The args/kwargs arguments support Attrib classes in the parameters for
        delayed evaluation of inputs until run-time. Example usage:
        task = Celery(wfspec, 'MyTask', 'celery.call',
                 call_args=['hello', 'world', Attrib('number')],
                 any_param=Attrib('result'))

        For serialization, the celery task_id is stored in internal_data,
        but the celery async call is only storred as an attr of the task (since
        it is not always serializable). When deserialized, the async_call attr
        is reset in the _try_fire call.

        :type  parent: TaskSpec
        :param parent: A reference to the parent task spec.
        :type  name: str
        :param name: The name of the task spec.
        :type  call: str
        :param call: The name of the celery task that needs to be called.
        :type  call_args: list
        :param call_args: args to pass to celery task.
        :type  call_result_key: str
        :param call_result_key: The key to use to store the results of the call in
                task.data. If None, then dicts are expanded into
                data and values are stored in 'result'.
        :param merge_results: merge the results in instead of overwriting existing
                fields.
        :type  kwargs: dict
        :param kwargs: kwargs to pass to celery task.
        """
        if not have_celery:
            raise Exception("Unable to import python-celery imports.")
        assert parent is not None
        assert name is not None
        if call is None:
            call = name

        TaskSpec.__init__(self, parent, name, **kwargs)
        self.description = kwargs.pop('description', '')
        self.call = call
        self.args = call_args
        self.call_queue = call_queue
        self.call_server_id = call_server_id
        self.merge_results = merge_results
        skip = 'data', 'defines', 'pre_assign', 'post_assign', 'lock'
        self.kwargs = dict(i for i in kwargs.iteritems() if i[0] not in skip)
        self.call_result_key = call_result_key
        LOG.debug("Celery task '%s' created to call '%s'", name, call)
Example #10
0
    def __init__(self, parent, **kwargs):
        """
        Constructor. The name of this task is *always* 'Start'.

        :type  parent: TaskSpec
        :param parent: A reference to the parent task spec.
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        TaskSpec.__init__(self, parent, 'Start', **kwargs)
Example #11
0
 def __init__(self, parent, **kwargs):
     """
     Constructor. The name of this task is *always* 'Start'.
     
     @type  parent: TaskSpec
     @param parent: A reference to the parent task spec.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, 'Start', **kwargs)
Example #12
0
 def __init__(self, parent, **kwargs):
     """
     Constructor. The name of this task is *always* 'ThreadStart'.
     
     :type  parent: TaskSpec
     :param parent: A reference to the parent task spec.
     :type  kwargs: dict
     :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, 'ThreadStart', **kwargs)
     self.internal = True
 def __init__(self, parent, **kwargs):
     """
     Constructor. The name of this task is *always* 'ThreadStart'.
     
     @type  parent: TaskSpec
     @param parent: A reference to the parent task spec.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, 'ThreadStart', **kwargs)
     self.internal = True
Example #14
0
 def _on_complete_hook(self, my_task):
     context = my_task.workflow.get_task_spec_from_name(self.context)
     triggered = []
     for task in my_task.workflow.task_tree:
         if task.thread_id != my_task.thread_id:
             continue
         if task.task_spec == context:
             task.trigger(self.choice)
             triggered.append(task)
     for task in triggered:
         context._predict(task)
     TaskSpec._on_complete_hook(self, my_task)
Example #15
0
 def _on_complete_hook(self, my_task):
     context = my_task.workflow.get_task_spec_from_name(self.context)
     triggered = []
     for task in my_task.workflow.task_tree:
         if task.thread_id != my_task.thread_id:
             continue
         if task.task_spec == context:
             task.trigger(self.choice)
             triggered.append(task)
     for task in triggered:
         context._predict(task)
     TaskSpec._on_complete_hook(self, my_task)
Example #16
0
    def __init__(self,
                 parent,
                 name,
                 call,
                 call_args=None,
                 result_key=None,
                 merge_results=False,
                 **kwargs):
        """Constructor.

        The args/kwargs arguments support Attrib classes in the parameters for
        delayed evaluation of inputs until run-time. Example usage:
        task = Celery(wfspec, 'MyTask', 'celery.call',
                 call_args=['hello', 'world', Attrib('number')],
                 any_param=Attrib('result'))

        For serialization, the celery task_id is stored in internal_attributes,
        but the celery async call is only storred as an attr of the task (since
        it is not always serializable). When deserialized, the async_call attr
        is reset in the try_fire call.

        @type  parent: TaskSpec
        @param parent: A reference to the parent task spec.
        @type  name: str
        @param name: The name of the task spec.
        @type  call: str
        @param call: The name of the celery task that needs to be called.
        @type  call_args: list
        @param call_args: args to pass to celery task.
        @type  result_key: str
        @param result_key: The key to use to store the results of the call in
                task.attributes. If None, then dicts are expanded into
                attributes and values are stored in 'result'.
        @param merge_results: merge the results in instead of overwriting existing
                fields.
        @type  kwargs: dict
        @param kwargs: kwargs to pass to celery task.
        """
        assert parent is not None
        assert name is not None
        assert call is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.description = kwargs.pop('description', '')
        self.call = call
        self.args = call_args
        self.merge_results = merge_results
        self.kwargs = {key: kwargs[key] for key in kwargs if key not in \
                ['properties', 'defines', 'pre_assign', 'post_assign', 'lock']}
        self.result_key = result_key
        LOG.debug("Celery task '%s' created to call '%s'" % (name, call))
Example #17
0
    def __init__(self, parent, name, call=None, call_args=None, call_queue=None, call_server_id=None,
                call_result_key=None, merge_results=True, **kwargs):
        """Constructor.

        The args/kwargs arguments support Attrib classes in the parameters for
        delayed evaluation of inputs until run-time. Example usage:
        task = Celery(wfspec, 'MyTask', 'celery.call',
                 call_args=['hello', 'world', Attrib('number')],
                 any_param=Attrib('result'))

        For serialization, the celery task_id is stored in internal_data,
        but the celery async call is only storred as an attr of the task (since
        it is not always serializable). When deserialized, the async_call attr
        is reset in the _try_fire call.

        :type  parent: TaskSpec
        :param parent: A reference to the parent task spec.
        :type  name: str
        :param name: The name of the task spec.
        :type  call: str
        :param call: The name of the celery task that needs to be called.
        :type  call_args: list
        :param call_args: args to pass to celery task.
        :type  call_result_key: str
        :param call_result_key: The key to use to store the results of the call in
                task.data. If None, then dicts are expanded into
                data and values are stored in 'result'.
        :param merge_results: merge the results in instead of overwriting existing
                fields.
        :type  kwargs: dict
        :param kwargs: kwargs to pass to celery task.
        """
        if not have_celery:
            raise Exception("Unable to import python-celery imports.")
        assert parent  is not None
        assert name    is not None
        if call is None:
            call = name

        TaskSpec.__init__(self, parent, name, **kwargs)
        self.description = kwargs.pop('description', '')
        self.call = call
        self.args = call_args
        self.call_queue = call_queue
        self.call_server_id = call_server_id
        self.merge_results = merge_results
        skip = 'data', 'defines', 'pre_assign', 'post_assign', 'lock'
        self.kwargs = dict(i for i in kwargs.iteritems() if i[0] not in skip)
        self.call_result_key = call_result_key
        LOG.debug("Celery task '%s' created to call '%s'", name, call)
Example #18
0
    def __init__(self, parent, name, success=False, **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  success: bool
        @param success: Whether to cancel successfully or unsuccessfully.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.cancel_successfully = success
Example #19
0
    def __init__(self, parent, name, success=False, **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  success: bool
        :param success: Whether to cancel successfully or unsuccessfully.
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.cancel_successfully = success
Example #20
0
    def _on_complete_hook(self, my_task):
        """
        A hook into _on_complete() that does the task specific work.

        :type  my_task: Task
        :param my_task: A task in which this method is executed.
        :rtype:  bool
        :returns: True on success, False otherwise.
        """
        for i in range(self.times + self.queued):
            for task_name in self.context:
                task = my_task.workflow.get_task_spec_from_name(task_name)
                task._on_trigger(my_task)
        self.queued = 0
        TaskSpec._on_complete_hook(self, my_task)
Example #21
0
 def __init__(self, parent, name, times = 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  times: int
     :param times: The number of tasks to create.
     :type  kwargs: dict
     :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times = times
Example #22
0
    def _on_complete_hook(self, my_task):
        """
        A hook into _on_complete() that does the task specific work.

        :type  my_task: Task
        :param my_task: A task in which this method is executed.
        :rtype:  bool
        :returns: True on success, False otherwise.
        """
        for i in range(self.times + self.queued):
            for task_name in self.context:
                task = my_task.workflow.get_task_spec_from_name(task_name)
                task._on_trigger(my_task)
        self.queued = 0
        TaskSpec._on_complete_hook(self, my_task)
Example #23
0
 def __init__(self, parent, name, times = 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  times: int
     @param times: The number of tasks to create.
     @type  kwargs: dict
     @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times = times
 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  times: int
     @param times: The number of tasks to create.
     @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)
Example #25
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 acquired.
        :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 #26
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 acquired.
        @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 #27
0
 def _on_complete_hook(self, my_task):
     context = my_task.workflow.get_task_spec_from_name(self.context)
     for task in my_task.workflow.task_tree:
         if task.thread_id != my_task.thread_id:
             continue
         if task.task_spec == context:
             task.trigger(self.choice)
     return TaskSpec._on_complete_hook(self, my_task)
Example #28
0
    def __init__(self, parent, name, args=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  args: list
        :param args: args to pass to process (first arg is the command).
        :type  kwargs: dict
        :param kwargs: kwargs to pass-through to TaskSpec initializer.
        """
        assert parent  is not None
        assert name    is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.args = args
Example #29
0
    def __init__(self, parent, name, call, call_args=None, result_key=None,
                 merge_results=False, **kwargs):
        """Constructor.

        The args/kwargs arguments support Attrib classes in the parameters for
        delayed evaluation of inputs until run-time. Example usage:
        task = Celery(wfspec, 'MyTask', 'celery.call',
                 call_args=['hello', 'world', Attrib('number')],
                 any_param=Attrib('result'))

        For serialization, the celery task_id is stored in internal_attributes,
        but the celery async call is only storred as an attr of the task (since
        it is not always serializable). When deserialized, the async_call attr
        is reset in the try_fire call.

        @type  parent: TaskSpec
        @param parent: A reference to the parent task spec.
        @type  name: str
        @param name: The name of the task spec.
        @type  call: str
        @param call: The name of the celery task that needs to be called.
        @type  call_args: list
        @param call_args: args to pass to celery task.
        @type  result_key: str
        @param result_key: The key to use to store the results of the call in
                task.attributes. If None, then dicts are expanded into
                attributes and values are stored in 'result'.
        @param merge_results: merge the results in instead of overwriting existing
                fields.
        @type  kwargs: dict
        @param kwargs: kwargs to pass to celery task.
        """
        assert parent  is not None
        assert name    is not None
        assert call is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.description = kwargs.pop('description', '')
        self.call = call
        self.args = call_args
        self.merge_results = merge_results
        self.kwargs = {key: kwargs[key] for key in kwargs if key not in \
                ['properties', 'defines', 'pre_assign', 'post_assign', 'lock']}
        self.result_key = result_key
        LOG.debug("Celery task '%s' created to call '%s'" % (name, call))
Example #30
0
 def _update_state_hook(self, my_task):
     context_task = my_task.workflow.get_task_spec_from_name(self.context)
     root_task    = my_task.workflow.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 #31
0
    def __init__(self, parent, name, context, **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  context: str
        @param context: The name of the task that needs to complete before
                        this task can execute.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent  is not None
        assert name    is not None
        assert context is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
Example #32
0
    def __init__(self, parent, name, context, **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  context: str
        @param context: The name of the task that needs to complete before
                        this task can execute.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        assert context is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
Example #33
0
 def _update_state_hook(self, my_task):
     context_task = my_task.workflow.get_task_spec_from_name(self.context)
     root_task = my_task.workflow.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 #34
0
    def __init__(self, parent, name, context, **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  context: str
        @param context: A list of the names of tasks that are to be triggered.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        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
    def test(self):
        """
        Checks whether all required attributes are set. Throws an exception
        if an error was detected.
        """
        #This has been overidden to allow a single default flow out (without a condition) - useful for
        #the converging type
        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
        if self.default_task_spec is None:
            raise WorkflowException(self, 'A default output is required.')
Example #36
0
    def __init__(self, parent, name, context, **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  context: str
        @param context: A list of the names of tasks that are to be triggered.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        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 #37
0
    def __init__(self, parent, name, transforms=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  transforms: list
        @param transforms: The commands that this task will execute to
                        transform data. The commands will be executed using the
                        python 'exec' function. Accessing inputs and outputs is
                        achieved by referencing the my_task.* and self.*
                        variables'
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent  is not None
        assert name    is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.transforms = transforms
Example #38
0
 def test(self):
     """
     Checks whether all required attributes are set. Throws an exception
     if an error was detected.
     """
     #This has been overidden to allow a single default flow out (without a condition) - useful for
     #the converging type
     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
     if self.default_task_spec is None:
         raise WorkflowException(self, 'A default output is required.')
Example #39
0
    def __init__(self, parent, name, transforms=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  transforms: list
        :param transforms: The commands that this task will execute to
                        transform data. The commands will be executed using the
                        python 'exec' function. Accessing inputs and outputs is
                        achieved by referencing the my_task.* and self.*
                        variables'
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.transforms = transforms
Example #40
0
    def __init__(self, parent, name, context, choice = 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  context: str
        @param context: The name of the MultiChoice that is instructed to
                        select the specified outputs.
        @type  choice: list(TaskSpec)
        @param choice: The list of task specs that is selected.
        @type  kwargs: dict
        @param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        assert context is not None
        #HACK: inherit from TaskSpec (not Trigger) on purpose.
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
        self.choice  = choice is not None and choice or []
Example #41
0
    def __init__(self, parent, name, context, times = 1, **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  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}.
        """
        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   = times
        self.queued  = 0
Example #42
0
    def __init__(self, parent, name, context, choice = 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  context: str
        :param context: The name of the MultiChoice that is instructed to
                        select the specified outputs.
        :type  choice: list(TaskSpec)
        :param choice: The list of task specs that is selected.
        :type  kwargs: dict
        :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
        """
        assert parent is not None
        assert name is not None
        assert context is not None
        #HACK: inherit from TaskSpec (not Trigger) on purpose.
        TaskSpec.__init__(self, parent, name, **kwargs)
        self.context = context
        self.choice  = choice is not None and choice or []
Example #43
0
    def __init__(self, parent, name, context, times=1, **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  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}.
        """
        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 = times
        self.queued = 0
Example #44
0
 def __init__(self,
              parent,
              name,
              times = None,
              times_attribute = None,
              suppress_threadstart_creation = False,
              **kwargs):
     """
     Constructor.
     
     :type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
     :param parent: A reference to the parent (usually a workflow).
     :type  name: string
     :param name: A name for the task.
     :type  times: int or None
     :param times: The number of tasks to create.
     :type  times_attribute: str or None
     :param times_attribute: The name of a data field that specifies
                             the number of outgoing tasks.
     :type  suppress_threadstart_creation: bool
     :param suppress_threadstart_creation: Don't create a ThreadStart, because
                                           the deserializer is about to.
     :type  kwargs: dict
     :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     if not times_attribute and not times:
         raise ValueError('require times or times_attribute argument')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times_attribute = times_attribute
     self.times           = times
     if not suppress_threadstart_creation:
         self.thread_starter  = ThreadStart(parent, **kwargs)
         self.outputs.append(self.thread_starter)
         self.thread_starter._connect_notify(self)
     else:
         self.thread_starter = None
Example #45
0
 def __init__(self,
              parent,
              name,
              times=None,
              times_attribute=None,
              suppress_threadstart_creation=False,
              **kwargs):
     """
     Constructor.
     
     :type  parent: L{SpiffWorkflow.specs.WorkflowSpec}
     :param parent: A reference to the parent (usually a workflow).
     :type  name: string
     :param name: A name for the task.
     :type  times: int or None
     :param times: The number of tasks to create.
     :type  times_attribute: str or None
     :param times_attribute: The name of a data field that specifies
                             the number of outgoing tasks.
     :type  suppress_threadstart_creation: bool
     :param suppress_threadstart_creation: Don't create a ThreadStart, because
                                           the deserializer is about to.
     :type  kwargs: dict
     :param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
     """
     if not times_attribute and not times:
         raise ValueError('require times or times_attribute argument')
     TaskSpec.__init__(self, parent, name, **kwargs)
     self.times_attribute = times_attribute
     self.times = times
     if not suppress_threadstart_creation:
         self.thread_starter = ThreadStart(parent, **kwargs)
         self.outputs.append(self.thread_starter)
         self.thread_starter._connect_notify(self)
     else:
         self.thread_starter = None
Example #46
0
 def _on_complete_hook(self, my_task):
     if self.transforms:
         for transform in self.transforms:
             exec(transform)
     return TaskSpec._on_complete_hook(self, my_task)
Example #47
0
 def _on_complete_hook(self, my_task):
     if self.transforms:
         for transform in self.transforms:
             exec(transform)
     return TaskSpec._on_complete_hook(self, my_task)
Example #48
0
 def create_instance(self):
     if 'testtask' in self.wf_spec.task_specs:
         del self.wf_spec.task_specs['testtask']
     return TaskSpec(self.wf_spec, 'testtask', description='foo')
Example #49
0
 def _on_complete_hook(self, my_task):
     for task_name in self.context:
         cancel_tasks = my_task.workflow.get_task_spec_from_name(task_name)
         for cancel_task in my_task._get_root()._find_any(cancel_tasks):
             cancel_task.cancel()
     TaskSpec._on_complete_hook(self, my_task)
Example #50
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 #51
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 #52
0
 def test(self):
     TaskSpec.test(self)
Example #53
0
 def _on_complete_hook(self, my_task):
     my_task._assign_new_thread_id()
     TaskSpec._on_complete_hook(self, my_task)
Example #54
0
 def _on_complete_hook(self, my_task):
     return TaskSpec._on_complete_hook(self, my_task)
Example #55
0
 def _on_complete_hook(self, my_task):
     my_task.workflow.cancel(self.cancel_successfully)
     TaskSpec._on_complete_hook(self, my_task)