def run(self): while not self.should_stop: task = self.queue.get() if task is self.tombstone: # Ensure any other threads also get the tombstone. self.queue.put(task) break try: for attempt in six.moves.range(self.conf.retries + 1): if self.should_stop: break LOG.info("Attempt number: %s to run task: %s ", attempt + 1, task.name) try: task.run() if task.success: break except Exception: LOG.exception('Unhandled error when running %s', task.name) # try again... task.reset() if task.success and not self.should_stop: for next_task in task.followups: LOG.info('Added next task %s to queue', next_task.name) self.queue.put(next_task) finally: self.queue.task_done()
def run(self): while not self.should_stop: task = self.queue.get() if task is self.tombstone: # Ensure any other threads also get the tombstone. self.queue.put(task) break try: for attempt in six.moves.range(self.conf.retries + 1): if self.should_stop: break if attempt > 0: LOG.info("Attempting to run task %s for the %s time", task.name, attempt + 1) else: LOG.info("Attempting to run task %s for the first" " time", task.name) try: task.run() if task.success: break except Exception: LOG.exception('Unhandled error when running %s', task.name) # try again... task.reset() if task.success and not self.should_stop: for next_task in task.followups: LOG.info('Added next task %s to queue', next_task.name) self.queue.put(next_task) finally: self.queue.task_done()