9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/services/spree_cm_commissioner/oauth_access_tokens/cleanup_expired.rb', line 9
def call
cutoff_date = EXPIRATION_THRESHOLD_DAYS.days.ago
total_deleted = 0
Spree::OauthAccessToken
.where('revoked_at IS NOT NULL OR (expires_in IS NOT NULL AND 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
|