def _execute_steps(steps): """ Given a set of steps, executes them, logs the result, and returns the worst priority with a list of reasons for that result. :return: a tuple of (:class:`StepResult` constant., list of reasons) """ if len(steps) > 0: results = yield steps_to_effect(steps) severity = [ StepResult.FAILURE, StepResult.RETRY, StepResult.LIMITED_RETRY, StepResult.SUCCESS ] priority = sorted(results, key=lambda (status, reasons): severity.index(status)) worst_status = priority[0][0] results_to_log = [{ 'step': step, 'result': result, 'reasons': map(structure_reason, reasons) } for step, (result, reasons) in zip(steps, results)] reasons = reduce(operator.add, (x[1] for x in results if x[0] == worst_status)) else: worst_status = StepResult.SUCCESS results_to_log = reasons = [] yield msg('execute-convergence-results', results=results_to_log, worst_status=worst_status.name) yield do_return((worst_status, reasons))
def _execute_steps(steps): """ Given a set of steps, executes them, logs the result, and returns the worst priority with a list of reasons for that result. :return: a tuple of (:class:`StepResult` constant, list of :obj:`ErrorReason`) """ if len(steps) > 0: results = yield steps_to_effect(steps) severity = [StepResult.FAILURE, StepResult.RETRY, StepResult.LIMITED_RETRY, StepResult.SUCCESS] priority = sorted(results, key=lambda (status, reasons): severity.index(status)) worst_status = priority[0][0] results_to_log = [ {'step': step, 'result': result, 'reasons': map(structure_reason, reasons)} for step, (result, reasons) in zip(steps, results) ] reasons = reduce(operator.add, (x[1] for x in results if x[0] == worst_status)) else: worst_status = StepResult.SUCCESS results_to_log = reasons = [] yield msg('execute-convergence-results', results=results_to_log, worst_status=worst_status.name) yield do_return((worst_status, reasons))
def test_uses_step_request(self): """Steps are converted to requests.""" steps = [TestStep(Effect(Constant((StepResult.SUCCESS, 'foo')))), TestStep(Effect(Error(RuntimeError('uh oh'))))] effect = steps_to_effect(steps) self.assertIs(type(effect.intent), ParallelEffects) expected_exc_info = matches(MatchesException(RuntimeError('uh oh'))) self.assertEqual( sync_perform(test_dispatcher(), effect), [(StepResult.SUCCESS, 'foo'), (StepResult.RETRY, [ErrorReason.Exception(expected_exc_info)])])
def test_uses_step_request(self): """Steps are converted to requests.""" steps = [ TestStep(Effect(Constant((StepResult.SUCCESS, 'foo')))), TestStep(Effect(Error(RuntimeError('uh oh')))) ] effect = steps_to_effect(steps) self.assertIs(type(effect.intent), ParallelEffects) expected_exc_info = matches(MatchesException(RuntimeError('uh oh'))) self.assertEqual( sync_perform(test_dispatcher(), effect), [(StepResult.SUCCESS, 'foo'), (StepResult.RETRY, [ErrorReason.Exception(expected_exc_info)])])