Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails + sideqik... How to perform a task at a specific date and time

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

like image 614
magnetic Avatar asked May 02 '14 19:05

magnetic


People also ask

How Sidekiq works or how would you implement Sidekiq?

Sidekiq is an open-source framework that provides efficient background processing for Ruby applications. It uses Redis as an in-memory data structure to store all of its job and operational data. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs.

Is Sidekiq a FIFO?

Sidekiq reads jobs from a Redis queue, using the First In First Out (FIFO) model, to process jobs.

How does Sidekiq work in Rails?

Execution of Sidekiq in rails applicationWorker is similar to a ruby object so it is deployed to another object to handle the ruby process. Multiple Workers are executed parallelly if they perform async use during the worker call. After completing the process, it will be generated to an HTTP request.

Should I use Activejob Sidekiq?

If you build a web application you should minimize the amount of time spent responding to every user; a fast website means a happy user.


1 Answers

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)
like image 72
blotto Avatar answered Oct 21 '22 22:10

blotto