Added token cleanup job.
This commit is contained in:
parent
4d842718e9
commit
aae37c735b
3 changed files with 44 additions and 1 deletions
|
@ -199,7 +199,8 @@ cleanup old online notifications
|
||||||
|
|
||||||
def self.cleanup
|
def self.cleanup
|
||||||
OnlineNotification.where('created_at < ?', Time.zone.now - 12.months).delete_all
|
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
|
# notify all agents
|
||||||
User.of_role('Agent').each {|user|
|
User.of_role('Agent').each {|user|
|
||||||
|
|
|
@ -62,6 +62,19 @@ returns
|
||||||
token.user
|
token.user
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def generate_token
|
def generate_token
|
||||||
|
|
29
db/migrate/20150824000001_update_cleanup.rb
Normal file
29
db/migrate/20150824000001_update_cleanup.rb
Normal 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
|
Loading…
Reference in a new issue