From b801c480f5c179445d5b3fe6ad1fe97edd02a5e2 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Tue, 7 Jul 2015 17:47:49 +0200 Subject: [PATCH] Handle Redis errors better --- django_q/cluster.py | 8 +++++++- django_q/monitor.py | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index d981b9f..35efd03 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -294,7 +294,13 @@ def pusher(task_queue, e, list_key=Conf.Q_LIST, r=redis_client): """ logger.info(_('{} pushing tasks at {}').format(current_process().name, current_process().pid)) while True: - task = r.blpop(list_key, 1) + try: + task = r.blpop(list_key, 1) + except Exception as e: + logger.error(e) + # redis probably crashed. Let the sentinel handle it. + sleep(10) + break if task: task = task[1] task_queue.put(task) diff --git a/django_q/monitor.py b/django_q/monitor.py index 4540b5a..a602341 100644 --- a/django_q/monitor.py +++ b/django_q/monitor.py @@ -147,7 +147,10 @@ class Stat(Status): return '{}:{}'.format(Conf.Q_STAT, cluster_id) def save(self): - self.r.set(self.key, SignedPackage.dumps(self, True), 3) + try: + self.r.set(self.key, SignedPackage.dumps(self, True), 3) + except Exception as e: + logger.error(e) def empty_queues(self): return self.done_q_size + self.task_q_size == 0