0

I'm have a check_delivery method which uses Sidekiq to call the EasyPost api gem.

  def check_delivery
    if tracking_number.present?
      EasypostWorker.perform_async(tracking_number)
    end
  end

class EasypostWorker
  include Sidekiq::Worker

  def perform(tracking_number)
    EasyPost.api_key = Rails.application.secrets.easypost_api_key
    tracker = EasyPost::Tracker.create(tracking_code: tracking_number)
    tracker.status
  end
end

However this returns the 24 random char Sidekiq job id instead of the tracker status (ie, "out_for_delivery", "delivered", etc.)

What am I doing wrong?

2
  • 1
    This is because when calling perform_async it sends it to a background process and does not execute it immediately. What are you trying to do exactly?
    – axsuul
    Jun 6, 2015 at 18:03
  • In complement of @axsuul answer, you can use sidekiq-status to track your job progression and set up an ajax polling to display status to your users when your job is completed. Jun 6, 2015 at 18:23

1 Answer 1

2

The check_delivery method was calling the EasypostWorker, which returned the job id.

Apparently Sidekiq Workers don't return results like regular ruby classes and methods.

So I added a status attribute to my model and updated the attribute inside the Worker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.