I need to add a job to run in the background, which I can easily do by MyJob.perform_later(args)
.
But I need some wait time before the scheduling, say 1 minute.
So if I schedule the job, it should get enqueued after 1 minute.
One workaround I could think of is to add sleep to my job. For example:
class MyJob < ApplicationJob
def perform(args)
sleep 1.minute
code
more code
more code
end
end
Which enqueues it immediately but sleeps in execution(not what I am looking for). There should be a better way to achieve this.
CodePudding user response:
Well, you can set a wait option like
MyJob.set(wait: 1.minute).perform_later
By setting wait the job will be enqueued after 1 minute.
Reference: https://guides.rubyonrails.org/v4.2/active_job_basics.html#enqueue-the-job