def _maybe_reload_module(self, module, force_reload=False, reloader=None): if module not in sys.modules: logger.debug('importing module %s', module) return self.app.loader.import_from_cwd(module) elif force_reload: logger.debug('reloading module %s', module) return reload_from_cwd(sys.modules[module], reloader)
def start(self): """Starts the workers main loop.""" self.on_start() self._state = self.RUN if self.pidfile: self.pidlock = platforms.create_pidlock(self.pidfile) try: for i, component in enumerate(self.components): logger.debug('Starting %s...', qualname(component)) self._running = i + 1 if component: component.start() logger.debug('%s OK!', qualname(component)) except SystemTerminate: self.terminate() except Exception as exc: logger.error('Unrecoverable error: %r', exc, exc_info=True) self.stop() except (KeyboardInterrupt, SystemExit): self.stop() try: # Will only get here if running green, # makes sure all greenthreads have exited. self._shutdown_complete.wait() except IGNORE_ERRORS: pass
def start(self): """Starts the workers main loop.""" self.on_start() self._state = self.RUN if self.pidfile: self.pidlock = platforms.create_pidlock(self.pidfile) try: for i, component in enumerate(self.components): logger.debug('Starting %s...', qualname(component)) self._running = i + 1 if component: component.start() logger.debug('%s OK!', qualname(component)) except SystemTerminate: self.terminate() except Exception as exc: logger.error('Unrecoverable error: %r', exc, exc_info=True) self.stop() except (KeyboardInterrupt, SystemExit): self.stop() try: # Will only get here if running green, # makes sure all greenthreads have exited. self._shutdown_complete.wait() except IGNORE_ERRORS: pass
def _maybe_reload_module(self, module, force_reload=False, reloader=None): if module not in sys.modules: logger.debug('importing module %s', module) return self.app.loader.import_from_cwd(module) elif force_reload: logger.debug('reloading module %s', module) return reload_from_cwd(sys.modules[module], reloader)
def _shutdown(self, warm=True): what = 'Stopping' if warm else 'Terminating' if self._state in (self.CLOSE, self.TERMINATE): return self.app.loader.shutdown_worker() if self.pool: self.pool.close() if self._state != self.RUN or self._running != len(self.components): # Not fully started, can safely exit. self._state = self.TERMINATE self._shutdown_complete.set() return self._state = self.CLOSE for component in reversed(self.components): logger.debug('%s %s...', what, qualname(component)) if component: stop = component.stop if not warm: stop = getattr(component, 'terminate', None) or stop stop() self.timer.stop() self.consumer.close_connection() if self.pidlock: self.pidlock.release() self._state = self.TERMINATE self._shutdown_complete.set()
def reload(self, modules=None, reload=False, reloader=None): modules = self.app.loader.task_modules if modules is None else modules imp = self.app.loader.import_from_cwd for module in set(modules or ()): if module not in sys.modules: logger.debug('importing module %s', module) imp(module) elif reload: logger.debug('reloading module %s', module) reload_from_cwd(sys.modules[module], reloader) self.pool.restart()
def reload(self, modules=None, reload=False, reloader=None): modules = self.app.loader.task_modules if modules is None else modules imp = self.app.loader.import_from_cwd for module in set(modules or ()): if module not in sys.modules: logger.debug('importing module %s', module) imp(module) elif reload: logger.debug('reloading module %s', module) reload_from_cwd(sys.modules[module], reloader) self.pool.restart()
def graceful_stop(self): for step in self.consumer.steps: if type(step) not in self.requires: if hasattr(step, 'stop'): logger.debug('| Worker: stopping {}'.format(step)) step.stop(self.consumer) def fake_action(*args, **kwargs): msg = 'Worker: action is disabled while worker is in `stopping` state' logger.info(msg) raise Exception(msg) for action in self.get_restricted_control_actions(): Panel.data[action] = fake_action
def graceful_stop(self): for step in self.consumer.steps: if type(step) not in self.requires: if hasattr(step, 'stop'): logger.debug('| Worker: stopping {}'.format(step)) step.stop(self.consumer) def fake_action(*args, **kwargs): msg = 'Worker: action is disabled while worker is in `stopping` state' logger.info(msg) raise Exception(msg) for action in self.get_restricted_control_actions(): Panel.data[action] = fake_action
def reload(self, modules=None, reload=False, reloader=None): modules = self.app.loader.task_modules if modules is None else modules imp = self.app.loader.import_from_cwd for module in set(modules or ()): if module not in sys.modules: logger.debug('importing module %s', module) imp(module) elif reload: logger.debug('reloading module %s', module) reload_from_cwd(sys.modules[module], reloader) if self.consumer: self.consumer.update_strategies() self.consumer.reset_rate_limits() try: self.pool.restart() except NotImplementedError: pass
def reload(self, modules=None, reload=False, reloader=None): modules = self.app.loader.task_modules if modules is None else modules imp = self.app.loader.import_from_cwd for module in set(modules or ()): if module not in sys.modules: logger.debug('importing module %s', module) imp(module) elif reload: logger.debug('reloading module %s', module) reload_from_cwd(sys.modules[module], reloader) if self.consumer: self.consumer.update_strategies() self.consumer.reset_rate_limits() try: self.pool.restart() except NotImplementedError: pass
def _shutdown(self, warm=True): what = 'Stopping' if warm else 'Terminating' socket_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(SHUTDOWN_SOCKET_TIMEOUT) # Issue 975 if self._state in (self.CLOSE, self.TERMINATE): return self.app.loader.shutdown_worker() if self.pool: self.pool.close() if self._state != self.RUN or self._running != len(self.components): # Not fully started, can safely exit. self._state = self.TERMINATE self._shutdown_complete.set() return self._state = self.CLOSE for component in reversed(self.components): logger.debug('%s %s...', what, qualname(component)) if component: stop = component.stop if not warm: stop = getattr(component, 'terminate', None) or stop stop() self.timer.stop() self.consumer.close_connection() if self.pidlock: self.pidlock.release() self._state = self.TERMINATE socket.setdefaulttimeout(socket_timeout) self._shutdown_complete.set()
def on_timer_tick(self, delay): logger.debug('Timer wake-up! Next ETA %s secs.', delay)
def on_timer_tick(self, delay): logger.debug('Timer wake-up! Next eta %s secs.', delay)
def on_timer_tick(self, delay): logger.debug("Timer wake-up! Next eta %s secs.", delay)
def on_error(self, exc, intervals, _): msg = "Critical object is not available: %s\nTrying to consume again %s..." interval = next(intervals) logger.debug(msg, exc, humanize_seconds(interval, 'in', ' ')) return interval