File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ namespace :kracken do
4
+ namespace :sweep do
5
+ desc "Remove expired credentials after threshold days " \
6
+ "(default threshold is 90 days)"
7
+ task :credentials , %i[ threshold ] => :environment do |_t , args |
8
+ threshold = args . fetch ( :threshold ) { 90 } . to_i . days
9
+ timestamp = threshold . ago
10
+ Rails . logger . info "Clearing expired `Credentials` older than " \
11
+ "#{ threshold . inspect } (#{ timestamp } )"
12
+ expired = Credentials . where ( expires : true )
13
+ . where ( "expires_at < ?" , timestamp )
14
+ . destroy_all
15
+ . size
16
+ Rails . logger . info "Removed: #{ expired } credentials"
17
+ threshold *= 2
18
+ timestamp = threshold . ago
19
+ Rails . logger . info "Clearing legacy `Credentials` older than " \
20
+ "#{ threshold . inspect } (#{ timestamp } )"
21
+ legacy = Credentials . where ( expires : [ nil , false ] )
22
+ . where ( "updated_at < ?" , timestamp )
23
+ . destroy_all
24
+ . size
25
+ Rails . logger . info "Removed: #{ legacy } credentials"
26
+ end
27
+ end
28
+ end
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments