Search code examples
ruby-on-railsrubyrakedelayed-job

Ruby on rails, delayed job :run_at variable


I am running a job which send data to a rest api.

After the completion of all those requests, I need a 10 minute delay then a method will be called which will process on those sent requests.

def self.batch_task(batch_params)
    # a very long code
    Batch.delay.check_requests
end

My second method is check_requests

def self.check_requests
   puts 'hello darkness'
end

def check_requests
   self.check_requests
end

at the end, i am calling handle_asynchronously

handle_asynchronously :batch_task
handle_asynchronously :check_requests, :run_at => Proc.new { 10.minutes.from_now }

Batch_task runs correctly followed by check_reqeusts, but I am not getting any the 10-minute delay before the function check_requests. My rake job is working fine. I also see the hello_darkness output in the console of rake jobs.


Solution

  • Try using the delay like below in the batch_task method

    def self.batch_task(batch_params)
      # a very long code
      Batch.delay(run_at: 10.minutes.from_now).check_requests
    end
    
    handle_asynchronously :batch_task
    handle_asynchronously :check_requests