def process_tasks(queue=None, sleep=5.0, duration=0): """ Run tasks that are scheduled to run on the queue :param duration: Run task for this many seconds (0 or less to run forever) - default is 0 :param sleep: Sleep for this many seconds before checking for new tasks (if none were found) - default is 5 :param queue: Only process tasks on this named queue """ sig_manager = SignalManager() autodiscover() start_time = time.time() while (duration <= 0) or (time.time() - start_time) <= duration: if sig_manager.kill_now: # shutting down gracefully break if not tasks.run_next_task(queue): # there were no tasks in the queue, let's recover. close_connection() logger.debug('waiting for tasks') time.sleep(sleep) else: # there were some tasks to process, let's check if there is more work to do after a little break. time.sleep( random.uniform(sig_manager.time_to_wait[0], sig_manager.time_to_wait[1]))
def handle(self, *args, **options): duration = options.pop('duration', 0) sleep = options.pop('sleep', 5.0) queue = options.pop('queue', None) log_std = options.pop('log_std', False) sig_manager = SignalManager() if log_std: _configure_log_std() autodiscover() start_time = time.time() while (duration <= 0) or (time.time() - start_time) <= duration: if sig_manager.kill_now: # shutting down gracefully break if not self._tasks.run_next_task(queue): # there were no tasks in the queue, let's recover. close_connection() logger.debug('waiting for tasks') time.sleep(sleep) else: # there were some tasks to process, let's check if there is more work to do after a little break. time.sleep( random.uniform(sig_manager.time_to_wait[0], sig_manager.time_to_wait[1]))
def handle(self, *args, **options): is_dev = options.get('dev', False) self.sig_manager = SignalManager() if is_dev: reload_func = autoreload.run_with_reloader if VERSION < (2, 2): reload_func = autoreload.main reload_func(self.run, *args, **options) else: self.run(*args, **options)
def run_process_tasks(*args, **options): """Runs background tasks such as those in bot/tasks/pennychat """ process_tasks = ProcessTasks() process_tasks.sig_manager = SignalManager() process_tasks.run(*args, **options)