Added token cleanup job.

This commit is contained in:
Martin Edenhofer 2015-08-24 12:09:04 +02:00
parent 4d842718e9
commit aae37c735b
3 changed files with 44 additions and 1 deletions

View file

@ -199,7 +199,8 @@ cleanup old online notifications
def self.cleanup
OnlineNotification.where('created_at < ?', Time.zone.now - 12.months).delete_all
OnlineNotification.where('seen = ? AND created_at < ?', true, Time.zone.now - 1.days).delete_all
OnlineNotification.where('seen = ? AND created_at < ?', true, Time.zone.now - 12.hours).delete_all
OnlineNotification.where('seen = ? AND updated_at < ?', true, Time.zone.now - 2.hours).delete_all
# notify all agents
User.of_role('Agent').each {|user|

View file

@ -62,6 +62,19 @@ returns
token.user
end
=begin
cleanup old token
Token.cleanup
=end
def self.cleanup
Token.where('persistent IS ? AND created_at < ?', nil, Time.zone.now - 30.days).delete_all
true
end
private
def generate_token

View file

@ -0,0 +1,29 @@
class UpdateCleanup < ActiveRecord::Migration
def up
# delete old entries
Scheduler.create_or_update(
name: 'Delete old online notification entries.',
method: 'OnlineNotification.cleanup',
period: 2.hours,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
add_index :online_notifications, [:seen]
add_index :online_notifications, [:created_at]
add_index :online_notifications, [:updated_at]
Scheduler.create_or_update(
name: 'Delete old token entries.',
method: 'Token.cleanup',
period: 30.days,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
add_index :tokens, :persistent
end
end