Added cleanup job.
This commit is contained in:
parent
18a21170a2
commit
d8001f3c17
2 changed files with 33 additions and 0 deletions
|
@ -98,4 +98,22 @@ class RecentView < ApplicationModel
|
||||||
return if !record.respond_to?(:permission)
|
return if !record.respond_to?(:permission)
|
||||||
record.permission( current_user: user )
|
record.permission( current_user: user )
|
||||||
end
|
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
|
end
|
||||||
|
|
15
db/migrate/20150701000002_add_cleanup2.rb
Normal file
15
db/migrate/20150701000002_add_cleanup2.rb
Normal 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
|
Loading…
Reference in a new issue