def then(self, body: TNewStep) -> 'StepBuilder[TNewStep]': new_step = WorkflowStep(body) new_step.body = body self.workflow_builder.add_step(new_step) outcome = StepOutcome() outcome.next_step = new_step.id self.step.outcomes.append(outcome) return StepBuilder[TStep](new_step, self.workflow_builder)
def while_(self, condition: Callable[[Any, StepExecutionContext], bool]): new_step = WorkflowStep(While) new_step.body = While self.workflow_builder.add_step(new_step) step_builder = StepBuilder[TStep](new_step, self.workflow_builder) step_builder.input('condition', condition) outcome = StepOutcome() outcome.next_step = new_step.id self.step.outcomes.append(outcome) return step_builder
def for_each(self, collection: Callable[[Any, StepExecutionContext], List]): new_step = WorkflowStep(Foreach) new_step.body = Foreach self.workflow_builder.add_step(new_step) step_builder = StepBuilder[TStep](new_step, self.workflow_builder) step_builder.input('collection', collection) outcome = StepOutcome() outcome.next_step = new_step.id self.step.outcomes.append(outcome) return step_builder
def handle_step_exception(self, workflow: WorkflowInstance, definition: WorkflowDefinition, pointer: ExecutionPointer, step: WorkflowStep): pointer.status = ExecutionPointer.FAILED if step.error_behavior == WorkflowStep.RETRY: pointer.retry_count += 1 pointer.sleep_until = datetime.utcnow() + timedelta( seconds=10) #TODO: make confiurable step.prime_for_retry(pointer) elif step.error_behavior == WorkflowStep.SUSPEND: workflow.status = WorkflowInstance.SUSPENDED elif step.error_behavior == WorkflowStep.TERMINATE: workflow.status = WorkflowInstance.TERMINATED
def wait_for( self, event_name: str, event_key: Callable[[Any, StepExecutionContext], Any], effective_date=lambda data, context: datetime.utcnow() ) -> 'StepBuilder[WaitFor]': new_step = WorkflowStep(WaitFor) new_step.body = WaitFor self.workflow_builder.add_step(new_step) step_builder = StepBuilder[TStep](new_step, self.workflow_builder) step_builder.input('event_name', lambda data, context: event_name) step_builder.input('event_key', event_key) step_builder.input('effective_date', effective_date) outcome = StepOutcome() outcome.next_step = new_step.id self.step.outcomes.append(outcome) return step_builder
def start_with(self, body: TStep) -> StepBuilder[TStep]: new_step = WorkflowStep(body) new_step.body = body self.add_step(new_step) return StepBuilder[TStep](new_step, self)
def add_step(self, step: WorkflowStep): step.id = len(self.steps) self.steps.append(step)