Browse Source

Added token cleanup job.

Martin Edenhofer 9 years ago
parent
commit
aae37c735b

+ 2 - 1
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|

+ 13 - 0
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

+ 29 - 0
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