def run(self): listener = self._client.get_listener(self._queue) task = listener.claim_orphan() while task is not None: if task.status == "reserved": self._run_task(task) elif task.status == "started": while process_running(task.pid): time.sleep(0.1) task = listener.claim_orphan() while True: task = listener.listen() self._run_task(task)
def claim_orphan(self): for listener in self._queue.get_listeners(): host, pid = self._parse_name(listener) if host != self._hostname: continue if pid == self._pid: continue if process_running(pid): continue if self._queue.remove_listener(listener) == 0: # already claimed continue task_id = self._queue.reclaim_task(listener, self._name) if task_id is None: continue return self._task_factory(task_id) return None