Added cleanup jobs.

This commit is contained in:
Martin Edenhofer 2015-07-01 00:25:05 +02:00
parent a9aa324fd0
commit d73784e7fd
3 changed files with 69 additions and 0 deletions

View file

@ -118,4 +118,21 @@ return all activity entries of an user
list
end
=begin
cleanup old stream messages
ActivityStream.cleanup
optional you can parse the max oldest stream entries
ActivityStream.cleanup(4.months)
=end
def self.cleanup(diff = 4.months)
ActivityStream.where('created_at < ?', Time.zone.now - diff).delete_all
true
end
end

View file

@ -3,6 +3,7 @@
class OnlineNotification < ApplicationModel
belongs_to :type_lookup, class_name: 'TypeLookup'
belongs_to :object_lookup, class_name: 'ObjectLookup'
belongs_to :user
after_create :notify_clients_after_change
after_update :notify_clients_after_change
@ -188,4 +189,31 @@ returns:
)
end
=begin
cleanup old online notifications
OnlineNotification.cleanup
=end
def self.cleanup
OnlineNotification.where('created_at < ?', Time.zone.now - 12.months).delete_all
OnlineNotification.where('seen = ? AND created_at < ?', true, Time.zone.now - 4.months).delete_all
# notify all agents
users = Ticket::ScreenOptions.agents
users.each {|user|
Sessions.send_to(
user.id,
{
event: 'OnlineNotification::changed',
data: {}
}
)
}
true
end
end

View file

@ -0,0 +1,24 @@
class AddCleanup < ActiveRecord::Migration
def up
# delete old entries
Scheduler.create_or_update(
name: 'Delete old activity stream entries.',
method: 'ActivityStream.cleanup',
period: 1.day,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
Scheduler.create_or_update(
name: 'Delete old online notification entries.',
method: 'OnlineNotification.cleanup',
period: 1.day,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
end
end