8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/services/spree_cm_commissioner/cleanup_expired_access_tokens.rb', line 8
def call
cutoff_date = EXPIRATION_THRESHOLD_DAYS.days.ago
total_deleted = 0
Spree::OauthAccessToken
.where.not(expires_in: nil)
.where('created_at + make_interval(secs => expires_in) < ?', cutoff_date)
.in_batches(of: BATCH_SIZE) do |relation|
deleted_count = relation.delete_all
total_deleted += deleted_count
end
log_cleanup_result(total_deleted, cutoff_date)
success(total_deleted: total_deleted, cutoff_date: cutoff_date, batch_size: BATCH_SIZE, expiration_threshold_days: EXPIRATION_THRESHOLD_DAYS)
rescue StandardError => e
log_error(e)
failure(nil, e.message)
end
|