Skip to content

Commit

Permalink
Merge pull request seomoz#87 from Koalephant/Emit-Failed-From-Retry
Browse files Browse the repository at this point in the history
Ensure `QlessJob:retry` emits a `failed` message via pubsub
  • Loading branch information
scriptedworld authored Dec 10, 2020
2 parents a72cf28 + adb6355 commit 485e356
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 485e356

Please sign in to comment.