]> git.openstreetmap.org Git - rails.git/commitdiff
Move token expiry to a rake task
authorTom Hughes <tom@compton.nu>
Thu, 8 Aug 2024 19:45:10 +0000 (20:45 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 8 Aug 2024 19:45:10 +0000 (20:45 +0100)
lib/tasks/cleanup.rake [new file with mode: 0644]
script/cleanup [deleted file]

diff --git a/lib/tasks/cleanup.rake b/lib/tasks/cleanup.rake
new file mode 100644 (file)
index 0000000..8c95a17
--- /dev/null
@@ -0,0 +1,10 @@
+namespace :db do
+  desc "Expire old tokens"
+  task :expire_tokens => :environment do
+    OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all
+    OauthToken.where("invalidated_at < NOW() - INTERVAL '28 days'").delete_all
+    RequestToken.where("authorized_at IS NULL AND created_at < NOW() - INTERVAL '28 days'").delete_all
+    Doorkeeper::AccessGrant.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all
+    Doorkeeper::AccessToken.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all
+  end
+end
diff --git a/script/cleanup b/script/cleanup
deleted file mode 100755 (executable)
index e829be1..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.join(File.dirname(__FILE__), "..", "config", "environment")
-
-OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all
-OauthToken.where("invalidated_at < NOW() - INTERVAL '28 days'").delete_all
-RequestToken.where("authorized_at IS NULL AND created_at < NOW() - INTERVAL '28 days'").delete_all
-
-Doorkeeper::AccessGrant.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all
-Doorkeeper::AccessToken.where("revoked_at < NOW() - INTERVAL '28 days' OR (created_at + expires_in * INTERVAL '1 second') < NOW() - INTERVAL '28 days'").delete_all
-
-exit 0