From adb63554103f7071cb9270b9e615f930eafbbc59 Mon Sep 17 00:00:00 2001 From: Stephen Reay Date: Wed, 8 Apr 2020 13:50:44 +0700 Subject: [PATCH] Ensure `QlessJob:retry` emits a `failed` message via pubsub When a job has exhausted all retries, attempting to retry it will now cause it to emit a pubsub message on the 'failed' channel. Closes seomoz/qless-core#86 --- job.lua | 4 ++++ test/test_events.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/job.lua b/job.lua index 251a5d4..8481113 100644 --- a/job.lua +++ b/job.lua @@ -493,6 +493,10 @@ function QlessJob:retry(now, queue, worker, delay, group, message) })) end + if redis.call('zscore', 'ql:tracked', self.jid) ~= false then + Qless.publish('failed', self.jid) + end + -- Add this type of failure to the list of failures redis.call('sadd', 'ql:failures', group) -- And add this particular instance to the failed types diff --git a/test/test_events.py b/test/test_events.py index a4268bf..eb0775c 100644 --- a/test/test_events.py +++ b/test/test_events.py @@ -132,6 +132,21 @@ def test_failed_retries(self): 'data': '{"message":"Job exhausted retries in queue \\"queue\\"","jid":"jid","group":"failed-retries-queue","event":"failed","worker":"worker"}' }]) + def test_failed_retries_tracked(self): + '''We should hear chatter when a tagged job fails from retries''' + self.lua('config.set', 0, 'grace-period', 0) + self.lua('put', 0, 'worker', 'queue', 'jid', 'klass', {}, 0, 'retries', 0) + self.lua('track', 0, 'track', 'jid') + job = self.lua('pop', 0, 'queue', 'worker', 10)[0] + with self.lua: + self.assertEqual(self.lua( + 'retry', 0, 'jid', 'queue', 'worker', 0, 'group', 'message'), -1) + self.assertEqual(self.lua('get', 0, 'jid')['state'], 'failed') + self.assertEqual(self.lua.log, [{ + 'channel': 'ql:failed', + 'data': 'jid' + }]) + def test_advance(self): '''We should hear chatter when completing and advancing a job''' self.lua('put', 0, 'worker', 'queue', 'jid', 'klass', {}, 0)