def add_signature(self, signature, dependencies=None): """ Add signature to Workflow, returns created WorkflowNode instance """ node = WorkflowNode(signature) dependencies = dependencies if dependencies is not None else [] # if signature is already added then perhaps there is some bug in code if node.id in self.nodes: raise WorkflowException( "Looks like signature '{}' is already added to the workflow". format(signature)) self.nodes[node.id] = node for required_node in dependencies: node.add_dependency(required_node) return node
def from_dict(cls, workflow_dict): obj = cls() obj.nodes = { node_id: WorkflowNode.from_dict(node_dict) for node_id, node_dict in workflow_dict['nodes'].items() } for attr in cls.straight_serializables: setattr(obj, attr, workflow_dict[attr]) # need to treat stats in special way as stats may e.g. # have additional keys when version is updated obj.stats.update(workflow_dict['stats']) # workflow id was just set so reinitialize the logger obj.__init_logger() return obj