From aae37c735b12138c4cc2a61bb691a5d3ea009a90 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 24 Aug 2015 12:09:04 +0200 Subject: [PATCH] Added token cleanup job. --- app/models/online_notification.rb | 3 ++- app/models/token.rb | 13 +++++++++ db/migrate/20150824000001_update_cleanup.rb | 29 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150824000001_update_cleanup.rb diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 56da4add0..b0895abae 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -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| diff --git a/app/models/token.rb b/app/models/token.rb index 6b3efb539..646b278be 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -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 diff --git a/db/migrate/20150824000001_update_cleanup.rb b/db/migrate/20150824000001_update_cleanup.rb new file mode 100644 index 000000000..41cdcc190 --- /dev/null +++ b/db/migrate/20150824000001_update_cleanup.rb @@ -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