Search code examples
ruby-on-railssidekiq

Pass job results to other job with Sidekiq


I make an API call to fetch an email address. On success I'd like to pass this email address to another job. I use sidekiq and sidekiq-batch gems.

class HandleWebhookJob
  def perform
    batch = Sidekiq::Batch.new
    batch.description = "Handling webhook"
    batch.on(:success, HandleWebhookJob::OtherJob, { email: @email })
    batch.jobs do
      @email = GetEmailJob.perform_async # returns email address
    end
  end

  class OtherJob
    def on_success(status, options)
      puts options # no email address here - nil
      # need to pass it to UseEmailJob.perfom_async(options[:email])
    end
  end
end

I assume that assigning the result of GetEmailJob to @email won't work. Can't find an example of how to do this and if it's even possible.


Solution

  • I think that you get jid in @email. Can you save emails in GetEmailJob to some storage (e.g. redis) with prefix:jid key and take them from there?