def _deserialize_task(self, workflow, s_state):
        assert isinstance(workflow, Workflow)
        # task_spec
        task_spec = workflow.get_task_spec_from_name(s_state['task_spec'])
        task = Task(workflow, task_spec)

        # id
        task.id = s_state['id']

        # parent
        # as the task_tree might not be complete yet
        # keep the ids so they can be processed at the end
        task.parent = s_state['parent']

        # children
        task.children = [
            self._deserialize_task(workflow, c) for c in s_state['children']
        ]

        # state
        task._state = s_state['state']
        task.triggered = s_state['triggered']

        # last_state_change
        task.last_state_change = s_state['last_state_change']

        # data
        task.data = s_state['data']

        # internal_data
        #if 'subworkflow' in s_state['internal_data']:
        #
        task.internal_data = self._deserialize_dict(s_state['internal_data'])

        return task
    def _deserialize_task(self, workflow, s_state):
        assert isinstance(workflow, Workflow)
        # task_spec
        task_spec = workflow.get_task_spec_from_name(s_state['task_spec'])
        task = Task(workflow, task_spec)

        # id
        task.id = s_state['id']

        # parent
        task.parent = workflow.get_task(s_state['parent'])

        # children
        task.children = [
            self._deserialize_task(workflow, c) for c in s_state['children']
        ]

        # state
        task._state = s_state['state']
        task.triggered = s_state['triggered']

        # last_state_change
        task.last_state_change = s_state['last_state_change']

        # attributes
        task.attributes = s_state['attributes']

        # internal_attributes
        task.internal_attributes = s_state['internal_attributes']

        return task
예제 #3
0
    def _retry_failed_task_clone(self, failed_task):
        '''
        Retry failed task by cloning it, leaving exisitng task as is. 
        (marat): personally a like this way much better, then _retry_failed_task(), but 
        there is a problem with leaving failed_task in ERROR state, 
        cause workflow becomes incompleted forever
        '''
        cloned_task = Task(failed_task.workflow,
                           failed_task.task_spec,
                           parent=failed_task.parent,
                           state=Task.FUTURE,
                           internal_data={
                               'error_data':
                               failed_task.internal_data['error_data']
                           })
        # Correct position
        siblings = failed_task.parent.children
        siblings.pop()
        siblings.insert(siblings.index(failed_task) + 1, cloned_task)

        for child in failed_task.children[:]:
            if child.task_spec in failed_task.task_spec.outputs:
                cloned_task.children.append(child)
                failed_task.children.remove(child)

        cloned_task.task_spec._update_state(cloned_task)
    def _deserialize_task(self, workflow, s_state):
        assert isinstance(workflow, Workflow), ("The workflow parameter did "
                                                "not receive a Workflow "
                                                "object. Instead, it got a "
                                                "'%s'" % workflow.__class__)
        # task_spec
        task_spec = workflow.get_task_spec_from_name(s_state['task_spec'])
        if task_spec.name == "Root":  # Don't create two roots
            task = workflow.task_tree
        else:
            task = Task(workflow, task_spec)

        # id
        task.id = s_state['id']

        # parent
        task.parent = workflow.get_task(s_state['parent'])
        # We need to add children in before deserializing child tasks so they can
        # find their parent (Task.Iter uses children to traverse the hierarchy
        if task.parent and task not in task.parent.children:
            task.parent.children.append(task)
        #assert task.parent is not None or task.get_name() == 'Root', ("Task "
        #    "'%s' parent is None" % task.get_name())

        # children
        for c in s_state['children']:
            self._deserialize_task(workflow, c)

        # state
        task._state = s_state['state']

        # last_state_change
        task.last_state_change = s_state['last_state_change']

        # attributes
        task.attributes = s_state['attributes']

        # internal_attributes
        task.internal_attributes = s_state['internal_attributes']

        return task