Reputation: 765
I've been doing some research but I can't figure out on how to do this in Rails
.
I need to execute some code after a certain amount of time. I found some gems
that can handle this but I don't want to use any.
I basically have a create
function in a Rails controller
and some stuff need to happen there after 24 hours.
EDIT: I tried with sleep
but it needs to be async
and sleep will stop everything from running until it's done, even if it is in a if
statement.
Upvotes: 0
Views: 280
Reputation: 2473
You need to create an ActionJob
with rails generate job your_job_name
.
Then you can delay its execution
YourJob.set(wait_until: 1.day.from_now)
For this to work you indeed need a Job queue to be configured for your project. I personally recommend Sidekiq
Sadly, you will have a hard time avoiding setting up a gem for this.
Upvotes: 5