Terng Gio
Terng Gio

Reputation: 69

Rails cron job to update status

I'm new to Rails cron job. Here's my question, I have an attribute called status and expiration date, let's say the expiration date is 2017/10/21, on that particular date, I want to update the status from Effect to Due, how am I supposed to do that. So far here's what I know,

every 1.day, :at => '12:00 am' do
 # do something here
end

It would be appretiated if somebody points me some direction.

Upvotes: 0

Views: 140

Answers (1)

Norly Canarias
Norly Canarias

Reputation: 1736

I think you should filter the records then update them. Something like this:

every 1.day, :at => '12:00 am' do
  Record.where(expiration_date: Date.today)
        .update_all(status: 'due')
end

Upvotes: 1

Related Questions