Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
        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.')
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def daemon_shutdown(*args, **kwargs):
    raise ShutdownException()