0

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

xps15z
  • 1,769
  • 1
  • 20
  • 38

1 Answers1

2

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.

Sebastian
  • 2,618
  • 3
  • 25
  • 32
  • That makes sense. Should I place the `scope :old, -> { where(["created_at < ?", 90.days.ago]) }` is a rake file? I have cron jobs setup for this already, I just found the whenever gem as I wanted something that could do it automatically so I don't have to continue manually entering in three different commands such as `rake remove_old_notifications`, etc. This is for the mailboxer gem fyi. – xps15z Apr 22 '14 at 15:11
  • Add this scope to each of class Notification, Conversation and Receipt. – Sebastian Apr 22 '14 at 17:47
  • is Capistrano required for this to work, and how can you test to see the results locally or does this only work in production – Serge Pedroza Feb 19 '15 at 22:09