Reputation: 123
I am looking to run a callback before (or when) a retry occurs for my Sidekiq worker jobs. We store the state of our jobs as an attribute (queued, performing, completed, etc.), and retries do not automatically reset this state. I need a way to run a callback that sets the retried job's state back to queued
before the retried job gets queued. For example:
before_retry do
self.status = "queued"
end
I read another post (Sidekiq Pro callback when batch is retried?) suggesting some sort of server middleware to detect retries and run callbacks, but I don't entirely know if that will work as I feel the retry would already be queued by the time any middleware catches it. Are there any other options out there? Thanks in advance!
Upvotes: 1
Views: 1162
Reputation: 2063
Would it work to rescue
inside perform
?
def perform
...
rescue YourException
self.status = "queued"
raise
end
raise
ing again so the job is retried.
Upvotes: 1