Save metadata to jobs on Sidekiq

Viewed 1170

Is it possible to save metadata to jobs when using Sidekiq?

For example, I want to execute a validation as a background job so that when it finishes, any errors encountered would be saved as metadata inside the job.

If this is possible, will I still be able to recover this metadata after the job is finished or dead?

Thanks in advance.

3 Answers

Yes, Sidekiq provides middleware (client & server) and the possibility to add metadata to the job.

  def call(worker_class, job, queue, redis_pool)
    # return false/nil to stop the job from going to redis
    return false if queue != 'default'
    job['customer'] = Customer.current_id
    yield
  end

Check this link for the docs.

Related