7

I am using https://github.com/mperham/sidekiq gem in a rails app to schedule tasks at a specific date and time.. Ex: Send appointment reminder 10minutes before the appointment schedule time.

class TextWorker
include Sidekiq::Worker

    def perform(appointer_id)
        number = Usermodel.find_by_id(appointer_id).contact
        Message.create(:from =>  email, 
                           :to =>   number,
                               :body => 'Thank you...Your appointment is at 10/1/2015 Sun, at 12pm')
    end

end

and calling it here in appointments controller:

class Appointments_controller

def create
    TextWorker.delay_until(10/20/2014, 13:40).perform_async(@user_contact)
end

delay_until doesn't work with specific date/time:

Is there any other way to perform a task at a specific date/time in sideqik? if so how? please

magnetic
  • 91
  • 1
  • 5
  • Maybe [this](http://stackoverflow.com/questions/20894740/sidekiq-schedule-same-worker-to-queue-when-done) helps – zishe May 02 '14 at 19:34

1 Answers1

5

you could pass in the calculated difference in order to send what sidekiq expects

e.g. DateTime.parse("10/20/2014")-DateTime.now

so :

  delay_interval = DateTime.parse("10/20/2014")-DateTime.now
  TextWorker.delay_until(delay_interval).perform_async(@user_contact)
blotto
  • 3,387
  • 1
  • 19
  • 19
  • 1
    Running Sidekiq 5.1.3 I had to do `perform_at(delay_time, @user_contact)` instead of `delay_until`. Or `perform_in` instead of `delay_for` and pass a time interval. – kaydanzie Sep 27 '19 at 17:52
  • @kaydanzie, are you running community version of Sidekiq 5.1.3 to perform perform_at(..., ..) ? – Kiran Patil Jan 06 '20 at 07:11