fix(archives): purge stuck pending archives
Cf 0cb096b3d6440a4da05ca2902ed6fa72a93e6579
This commit is contained in:
parent
f1957e51f8
commit
197fa54ea4
3 changed files with 20 additions and 10 deletions
|
@ -3,5 +3,6 @@ class Cron::PurgeStaleArchivesJob < Cron::CronJob
|
|||
|
||||
def perform
|
||||
Archive.stale(Archive::RETENTION_DURATION).destroy_all
|
||||
Archive.stuck(Archive::MAX_DUREE_GENERATION).destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ class Archive < ApplicationRecord
|
|||
include TransientModelsWithPurgeableJobConcern
|
||||
|
||||
RETENTION_DURATION = 4.days
|
||||
MAX_DUREE_GENERATION = 24.hours
|
||||
MAX_SIZE = 100.gigabytes
|
||||
|
||||
has_and_belongs_to_many :groupe_instructeurs
|
||||
|
|
|
@ -4,26 +4,34 @@ describe Archive do
|
|||
before { Timecop.freeze(Time.zone.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
let(:archive) { create(:archive, job_status: :pending) }
|
||||
let!(:archive) { create(:archive, job_status: :pending) }
|
||||
|
||||
describe 'scopes' do
|
||||
describe 'staled' do
|
||||
let(:recent_archive) { create(:archive, job_status: :pending) }
|
||||
let(:staled_archive_still_pending) { create(:archive, job_status: :pending, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
let(:staled_archive_still_failed) { create(:archive, job_status: :failed, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
let(:staled_archive_still_generated) { create(:archive, job_status: :generated, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
let!(:recent_archive) { create(:archive, job_status: :pending) }
|
||||
let!(:staled_archive_still_pending) { create(:archive, job_status: :pending, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
let!(:staled_archive_still_failed) { create(:archive, job_status: :failed, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
let!(:staled_archive_still_generated) { create(:archive, job_status: :generated, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
||||
|
||||
subject do
|
||||
archive
|
||||
recent_archive
|
||||
staled_archive_still_pending
|
||||
staled_archive_still_failed
|
||||
staled_archive_still_generated
|
||||
Archive.stale(Archive::RETENTION_DURATION)
|
||||
end
|
||||
|
||||
it { is_expected.to match_array([staled_archive_still_failed, staled_archive_still_generated]) }
|
||||
end
|
||||
|
||||
describe 'stuck' do
|
||||
let!(:recent_archive) { create(:archive, job_status: :pending) }
|
||||
let!(:staled_archive_still_pending) { create(:archive, job_status: :pending, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
||||
let!(:staled_archive_still_failed) { create(:archive, job_status: :failed, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
||||
let!(:staled_archive_still_generated) { create(:archive, job_status: :generated, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
||||
|
||||
subject do
|
||||
Archive.stuck(Archive::MAX_DUREE_GENERATION)
|
||||
end
|
||||
|
||||
it { is_expected.to match_array([staled_archive_still_pending]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.job_status' do
|
||||
|
|
Loading…
Reference in a new issue