Search code examples
ruby-on-railsrubytaskdelayed-jobjob-scheduling

Ruby on Rail - Add background task to update status and expiration date


I am making a auction web app. When a ad is created, I automatically add expiration date into database.

  before_create :set_expiration_date

  def set_expiration_date
    self.expiration_date =  Time.now + 60.days
  end 

How can I add a background task/job, so when a ad has reached its expiration date, it can change the status to false.

Is it any good gem that I could use in my case?

I have tried whenever gem and it was very cumbersome and it didn't ran in background and hard to understand.


Solution

  • Just create background job changing the status in after create callback which would be performed at exp. date

    more info: http://guides.rubyonrails.org/active_job_basics.html