Adding on job complete callback to sidekiq

Came across a use case at work where I wanted record the status of the job I schedule ( enqueued, failed, success ). On failure sidekiq calls sidekiq_retries_exhausted callback. But there is no callback when job is completed successfully. Lets implement this as a sidekiq middleware.

  • Write a middleware for sidekiq which calls the on job complete on the job instance if the method is present You can keep this in under configs

  • Register this middleware in sidekiq configuration

  • Now you can use this hook in your sidekiq jobs, for e.g. I have a job which gets some data from a url and write to cache