def run_forever(self): with WorkerDirectory(self.name): signal.signal(signal.SIGINT, self._signal_handler) signal.signal(signal.SIGTERM, self._signal_handler) while not self.shutdown_requested: for task in self.iter_tasks(): self.supervise_task(task) if not self.shutdown_requested: self.sleep() self.shutdown()
def run_forever(self): with WorkerDirectory(self.name): signal.signal(signal.SIGINT, self._signal_handler) signal.signal(signal.SIGTERM, self._signal_handler) # Subscribe to pgsql channels self.cursor.execute("LISTEN pulp_worker_wakeup") self.cursor.execute("LISTEN pulp_worker_cancel") while not self.shutdown_requested: for task in self.iter_tasks(): self.supervise_task(task) if not self.shutdown_requested: self.sleep() self.cursor.execute("UNLISTEN pulp_worker_cancel") self.cursor.execute("UNLISTEN pulp_worker_wakeup") self.shutdown()
def run_forever(self): with WorkerDirectory(self.name): signal.signal(signal.SIGINT, self._signal_handler) signal.signal(signal.SIGTERM, self._signal_handler) while not self.shutdown_requested: for task in self.iter_tasks(): try: # Workaround to block all other workers if task.name == "pulpcore.app.tasks.orphan.orphan_cleanup": suffix = "" else: suffix = "_shared" self.cursor.execute( f"SELECT pg_advisory_lock{suffix}(1234)") self.supervise_task(task) finally: self.cursor.execute( f"SELECT pg_advisory_unlock{suffix}(1234)") if not self.shutdown_requested: self.sleep() self.shutdown()
def register_birth(self, *args, **kwargs): """ Handle the birth of a RQ worker. This creates the working directory and removes any vestige records from a previous worker with the same name. Args: args (tuple): unused positional arguments kwargs (dict): unused keyword arguments """ mark_worker_offline(self.name, normal_shutdown=True) working_dir = WorkerDirectory(self.name) working_dir.delete() working_dir.create() return super().register_birth(*args, **kwargs)