Skip to content

Commit 9827b2d

Browse files
author
maelorn
committed
fix edge cases
1 parent 63c519b commit 9827b2d

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

mrq/job.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,14 @@ def _save_status(self, status, updates=None, exception=False, w=None, j=None):
484484
db_updates["traceback"] = trace
485485
db_updates["exceptiontype"] = exc.__name__
486486

487-
# get all data before updating them
488-
current_queue = (db_updates or {}).get("queue") or self.data["queue"]
489-
old_queue = self.data.get("queue")
490-
old_status = self.data.get("status")
491-
raw_queue = self.data.get("raw_queue")
492-
retry_count = self.data.get("retry_count", 0)
493-
494487
if self.data:
495488
self.data.update(db_updates)
489+
# get all data before updating them
490+
current_queue = (db_updates or {}).get("queue") or self.data["queue"]
491+
old_queue = self.data.get("queue")
492+
old_status = self.data.get("status")
493+
raw_queue = self.data.get("raw_queue")
494+
retry_count = self.data.get("retry_count", 0)
496495

497496
# In the most common case, we allow an optimization on Mongo writes
498497
if status == "success":
@@ -519,27 +518,28 @@ def _save_status(self, status, updates=None, exception=False, w=None, j=None):
519518
if exception:
520519
self._save_traceback_history(status, trace, exc)
521520

522-
with context.connections.redis.pipeline(transaction=False) as pipe:
523-
if status != "started":
524-
# Queue change
525-
if current_queue != old_queue:
526-
pipe.decr("queuesize:%s" % old_queue)
527-
if status == "queued":
521+
if self.data:
522+
with context.connections.redis.pipeline(transaction=False) as pipe:
523+
if status != "started":
524+
# Queue change
525+
if current_queue != old_queue:
526+
pipe.decr("queuesize:%s" % old_queue)
527+
if status == "queued":
528+
pipe.incr("queuesize:%s" % current_queue)
529+
530+
# Regular queues
531+
elif status == "queued" and old_status != "started":
528532
pipe.incr("queuesize:%s" % current_queue)
529533

530-
# Regular queues
531-
elif status == "queued" and old_status != "started":
532-
pipe.incr("queuesize:%s" % current_queue)
534+
elif status != "queued" and not raw_queue:
535+
pipe.decr("queuesize:%s" % current_queue)
533536

534-
elif status != "queued" and not raw_queue:
535-
pipe.decr("queuesize:%s" % current_queue)
536-
537-
# Raw queues retries
538-
elif (db_updates or {}).get("retry_count", 0) > retry_count:
539-
pipe.incr("queuesize:%s" % current_queue)
537+
# Raw queues retries
538+
elif (db_updates or {}).get("retry_count", 0) > retry_count:
539+
pipe.incr("queuesize:%s" % current_queue)
540540

541-
pipe.expire("queuesize:%s" % current_queue, context.get_current_config().get("queue_ttl"))
542-
pipe.execute()
541+
pipe.expire("queuesize:%s" % current_queue, context.get_current_config().get("queue_ttl"))
542+
pipe.execute()
543543

544544
def set_current_io(self, io_data):
545545

0 commit comments

Comments
 (0)