xps15z
xps15z

Reputation: 1829

Schedule tasks to remove table entries

Can someone assist me setting up a cron job using the whenever gem? I want to clear the Notifications, Conversations, and Receipts tables every 90 days from the created_at dates.

I'm not sure how to fill it in.

every 90.day, :at => '4:30 am' do end

Upvotes: 0

Views: 90

Answers (1)

Sebastian
Sebastian

Reputation: 2786

You are starting from a bad side. You should run task every day. The task will delete all Notification, Conversations and Receipts older than 90 days.

class Notification

   scope :old, -> { where(["created_at < ?", 90.days.ago]) }

end

# schedule.rb
every 1.day do
  runner "Notification.old.destroy"
end

Something like that.

Upvotes: 2

Related Questions