anthonymidili/Recipedia

View on GitHub
lib/tasks/clean_notifications.rake

Summary

Maintainability
Test Coverage
# Run "bundle exec rake clean_notifications" to perform.
desc "Clean old notifications"
task clean_notifications: :environment do
  puts "Cleaning notifications older than 1 month..."
  notifications = Notification.where('created_at < :time', time: (DateTime.current - 1.month))
  notifications.destroy_all
  puts "#{notifications.count} Notifications deleted... done."
end