class JoinTestFlow(Flow): start = flow.StartFunction().Next(this.split) split = flow.Split().Next(this.task1).Next(this.task2) task1 = flow.Function(func).Next(this.join) task2 = flow.Function(func).Next(this.join) join = flow.Join().Next(this.end) end = flow.End()
class JoinTestFlow(Flow): start = flow.StartFunction().Next(this.split) split = flow.Split().Next(this.task1).Next(this.task2) task1 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join) task2 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join) join = flow.Join().Next(this.end) end = flow.End()
class SplitJoinTestFlow(Flow): start = flow.StartFunction(create_test_flow).Next(this.split) split = flow.Split().Next(this.task1).Next(this.task2).Next( this.task3, cond=lambda process: False) task1 = flow.Function(function_task).Next(this.join) task2 = flow.Function(function_task).Next(this.join) task3 = flow.Function(function_task).Next(this.join) join = flow.Join().Next(this.end) end = flow.End()
class StartUndoFlow(Flow): start = flow.StartFunction(create_test_flow).Next(this.func_task) func_task = flow.Function(function_task).Next(this.end) end = flow.End() def start_undo(self, activation): self.handler_called = True
class ChildFlow(FlowMixin, BaseFlow): start = BaseFlow.start.Next(this.alert) alert = flow.Function(this.send_alert).Next(this.notify_admins) notify_users = FlowMixin.notify_users.Next(this.end) def send_alert(self, activation): activation.prepare() activation.done()
class Flow(FlowStub): func_task = flow.Function() method_called = False @method_decorator(flow.flow_func(task_loader=lambda flow_task: TaskStub())) def task_func(self, activation): activation.prepare() FlowStub.method_called = True activation.done() return activation
def test_function_with_default_activation(self): @flow.flow_func(task_loader=lambda flow_task: TaskStub()) def func_impl(activation): activation.prepare() activation.done() return activation flow_task = self.init_node(flow.Function(func_impl)) act = flow_task.run() self.assertEqual(act.task.status, STATUS.DONE)
class ChildFlow(FlowMixin, BaseFlow): start = BaseFlow.start.Next(this.alert) alert = flow.Function(this.send_alert).Next(this.notify_admins) notify_users = FlowMixin.notify_users.Next(this.end) def handler_execute(self, activation): raise NotImplementedError def send_alert(self, activation): activation.prepare() activation.done()
class FunctionFlow(Flow): process_cls = TestProcess start = flow.StartFunction(tasks.start_process) \ .Next(this.task1) task1 = flow.Handler(tasks.do_handler_task) \ .Next(this.task2) task2 = flow.Function(tasks.do_func_task) \ .Next(this.end) end = flow.End()
class FunctionFlow(Flow): start = flow.StartFunction(create_test_flow).Next(this.func_task) default_start = flow.StartFunction().Next(this.func_task) inline_start = flow.StartFunction().Next(this.func_task) func_task = flow.Function(function_task).Next(this.handler_task) handler_task = flow.Handler(handler).Next(this.end) end = flow.End() def inline_start_func(self, activation): activation.prepare() activation.done() self.inline_start_func_called = True return activation
class MyPizzaFlow(Flow): process_class = MyPizzaProcess start = ( flow.Start(CreateProcessView, fields=['content']) .Available(available_in_group('customers')) .Next(this.order_pizza) ) order_pizza = ( flow.Handler(this.save_content_to_order) .Next(this.external_join) ) # To run this, we need to know which task we are specifically referring to # This can be done by querying the database my_trigger = ( flow.Function(trigger_triggered, task_loader=lambda flow_task, task: task) .Next(this.external_join) ) external_join = ( flow.Join() .Next(this.take_the_order) ) take_the_order = ( flow.View(TakeTheOrderView, fields=['table_location']) .Permission('users.can_take_the_order') .Next(this.prepare_pizza) ) prepare_pizza = ( flow.View( UpdateProcessView ).Next(this.bring_pizza) ) bring_pizza = ( flow.End() # TODO continue ) def save_content_to_order(self, activation): order = Order() order.content = activation.process.content order.save() activation.process.order = order activation.process.save()
def test_function_activation_lifecycle(self): flow_task = self.init_node(flow.Function(lambda t: None)) act = FuncActivation() act.initialize(flow_task, TaskStub()) # execute act.prepare() act.done() self.assertEqual(act.task.status, STATUS.DONE) # undo act.undo() self.assertEqual(act.task.status, STATUS.NEW) act.cancel() self.assertEqual(act.task.status, STATUS.CANCELED)
class FlowEndTestFlow(Flow): start = flow.StartFunction().Next(this.task) task = flow.Function(lambda t: None).Next(this.end) end = flow.End()
class StartUndoFlow(Flow): start = flow.StartFunction(create_test_flow).Next(this.func_task) func_task = flow.Function(function_task).Next(this.end) end = flow.End()
class FunctionFlow(Flow): start = flow.StartFunction(create_test_flow).Next(this.func_task) func_task = flow.Function(function_task).Next(this.handler_task) handler_task = flow.Handler(handler).Next(this.end) end = flow.End()