def test_raises_on_failure(self): def custom_func(): group = Group() for i in range(0, 2): group.append(zero_division) return group fngrp = FuncGroup(custom_func, raises_on_failure=False) # We have to submit the funcgroup to create # the activities fngrp.submit(executor) self.assertFalse( fngrp.activities.activities[0].activity.raises_on_failure) def custom_func(): group = Group() for i in range(0, 2): group.append(zero_division) return group fngrp = FuncGroup(custom_func, raises_on_failure=True) # We have to submit the funcgroup to create # the activities with self.assertRaises(exceptions.TaskFailed): fngrp.submit(executor)
def test_propagate_attribute(self): """ Test that attribute 'raises_on_failure' is well propagated through FuncGroup. """ first = ActivityTask(running_task, "test1") intermediary_activities = Chain( (running_task, "test2"), (running_task, "test3"), ) last = ActivityTask(running_task, "test4") def custom_func(_): return intermediary_activities Chain(first, FuncGroup(custom_func), last, send_result=True, raises_on_failure=False).submit(executor) self.assertFalse(first.activity.raises_on_failure) self.assertFalse(last.activity.raises_on_failure) self.assertFalse( intermediary_activities.activities[0].activity.raises_on_failure) self.assertFalse( intermediary_activities.activities[1].activity.raises_on_failure)
def submit(self, executor): workflow = executor.workflow def fn_steps_done(steps_done): marker = { "step": self.step_name, "status": "scheduled", "forced": False, "reasons": [] } chain = Chain() forced_steps = workflow.get_forced_steps() skipped_steps = workflow.get_skipped_steps() if step_will_run(self.step_name, forced_steps, skipped_steps, steps_done, self.force): if step_is_forced(self.step_name, forced_steps, self.force): marker["forced"] = True marker["reasons"] = get_step_force_reasons( self.step_name, getattr(workflow, 'steps_forced_reasons', {}) ) marker_done = copy.copy(marker) marker_done["status"] = "completed" workflow.add_forced_steps(self.force_steps_if_executed, 'Dep of {}'.format(self.step_name)) chain += ( workflow.record_marker('log.step', marker), self.activities, (activity.Activity(MarkStepDoneTask, **workflow._get_step_activity_params()), workflow.get_step_bucket(), workflow.get_step_path_prefix(), self.step_name), workflow.record_marker('log.step', marker_done) ) else: marker["status"] = "skipped" if step_is_skipped_by_force(self.step_name, skipped_steps): marker["forced"] = True marker["reasons"] = get_step_skip_reasons( self.step_name, getattr(workflow, 'steps_skipped_reasons', {}) ) else: marker["reasons"] = ["Step was already played"] if self.activities_if_step_already_done: chain.append(self.activities_if_step_already_done) chain.append( workflow.record_marker('log.step', marker)) if self.emit_signal: chain.append( workflow.signal('step.{}'.format(self.step_name), propagate=False)) chain.bubbles_exception_on_failure = self.bubbles_exception_on_failure return chain return workflow.submit(Chain( workflow.get_steps_done_activity(), FuncGroup(fn_steps_done), send_result=True))
def test_previous_value_with_func(self): def custom_func(previous_value): group = Group() for i in range(0, previous_value): group.append(to_int, i * 2) return group chain = Chain((sum_values, [1, 2]), FuncGroup(custom_func), (sum_values, ), send_result=True).submit(executor) self.assertEqual(chain.result, [3, [0, 2, 4], 6])
def submit(self, executor): workflow = executor.workflow def fn_steps_done(steps_done): marker = { "step": self.step_name, "status": "scheduled", "forced": False, "reasons": [] } chain = Chain() if step_will_run(self.step_name, workflow.get_forced_steps(), steps_done, self.force): if step_is_forced(self.step_name, workflow.get_forced_steps(), self.force): marker["forced"] = True marker["reasons"] = get_step_force_reasons(self.step_name, workflow.steps_forced_reasons) workflow.add_forced_steps(self.force_steps_if_executed, 'Dep of {}'.format(self.step_name)) chain += ( self.activities, (activity.Activity(MarkStepDoneTask, **workflow._get_step_activity_params()), workflow.get_step_bucket(), workflow.get_step_path_prefix(), self.step_name), workflow.record_marker('log.step', marker) ) else: marker["status"] = "skipped" if self.activities_if_step_already_done: chain.append(self.activities_if_step_already_done) chain.append( workflow.record_marker('log.step', marker)) if self.emit_signal: chain.append( workflow.signal('step.{}'.format(self.step_name), propagate=False)) return chain return workflow.submit(Chain( workflow.get_steps_done_activity(), FuncGroup(fn_steps_done), send_result=True))
def test_raises_on_failure(self): def custom_func(): group = Group() for i in range(0, 2): group.append(zero_division) return group fngrp = FuncGroup(custom_func, raises_on_failure=False) # We have to submit the funcgroup to create # the activities fngrp.submit(executor) self.assertFalse(fngrp.activities.activities[0].activity.raises_on_failure) def custom_func(): group = Group() for i in range(0, 2): group.append(zero_division) return group fngrp = FuncGroup(custom_func, raises_on_failure=True) # We have to submit the funcgroup to create # the activities with self.assertRaises(exceptions.TaskFailed): fngrp.submit(executor)