def find_tasks_after_completion(task, workbook): """Determine tasks which should be scheduled after completing given task. Expression 'on_finish' is not mutually exclusive to 'on_success' and 'on_error'. :param task: Task object :param workbook: Workbook Entity :return: list of task dictionaries. """ state = task['state'] found_tasks = [] LOG.debug("Recieved task %s: %s" % (task['name'], state)) if state == states.ERROR: tasks_on_error = workbook.tasks.get(task['name']).get_on_error() if tasks_on_error: found_tasks = _get_tasks_to_schedule(tasks_on_error, workbook) elif state == states.SUCCESS: tasks_on_success = workbook.tasks.get(task['name']).get_on_success() if tasks_on_success: found_tasks = _get_tasks_to_schedule(tasks_on_success, workbook) if states.is_finished(state): tasks_on_finish = workbook.tasks.get(task['name']).get_on_finish() if tasks_on_finish: found_tasks += _get_tasks_to_schedule(tasks_on_finish, workbook) LOG.debug("Found tasks: %s" % found_tasks) workflow_tasks = [] for t in found_tasks: workflow_tasks += find_workflow_tasks(workbook, t.name) LOG.debug("Workflow tasks to schedule: %s" % workflow_tasks) return workflow_tasks
def is_finished(tasks): return all(states.is_finished(task['state']) for task in tasks)