def get_next_task(self): """Takes new task.""" if not self.worker_info["enabled"]: self.log_info("Worker is disabled.") return if not self.worker_info["ready"]: self.log_info("Worker is not ready to take another task.") return if self.locked: task_list = self.hub.worker.get_worker_tasks() if not task_list: raise ShutdownException() awaited_task_list = self.hub.worker.get_awaited_tasks(task_list) self.log_debug("Current awaited tasks: %r" % [ti["id"] for ti in awaited_task_list]) # process assigned tasks first for task_info in awaited_task_list: self.take_task(task_info) return assigned_task_list = self.hub.worker.get_tasks_to_assign() self.log_debug("Current assigned tasks: %r" % [ti["id"] for ti in assigned_task_list]) # process assigned tasks first for task_info in assigned_task_list: self.take_task(task_info)
def get_next_task_mock(): self.run_count += 1 if self.run_count >= self.max_runs: raise ShutdownException() if self.fail: raise Exception('This task always fails.')
def run(self): kill = self.args.get("kill", False) if kill: # raise exception and terminate immediately raise ShutdownException() # lock the task manager and let it terminate all tasks self.task_manager.locked = True
def daemon_shutdown(*args, **kwargs): raise ShutdownException()