Added cleanup job.

This commit is contained in:
Martin Edenhofer 2015-07-01 01:38:16 +02:00
parent 18a21170a2
commit d8001f3c17
2 changed files with 33 additions and 0 deletions

View file

@ -98,4 +98,22 @@ class RecentView < ApplicationModel
return if !record.respond_to?(:permission)
record.permission( current_user: user )
end
=begin
cleanup old entries
RecentView.cleanup
optional you can parse the max oldest entries
RecentView.cleanup(1.month)
=end
def self.cleanup(diff = 1.month)
RecentView.where('created_at < ?', Time.zone.now - diff).delete_all
true
end
end

View file

@ -0,0 +1,15 @@
class AddCleanup2 < ActiveRecord::Migration
def up
# delete old entries
Scheduler.create_or_update(
name: 'Delete old entries.',
method: 'RecentView.cleanup',
period: 1.day,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
end
end