mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 13:23:38 +08:00
FIX: Onceoff job to recover missing post uploads.
This fixes the regression due to 1f636c445b
This commit is contained in:
parent
529e4018f0
commit
aa1af9fc22
22
app/jobs/onceoff/recover_post_uploads.rb
Normal file
22
app/jobs/onceoff/recover_post_uploads.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
require_dependency "upload_recovery"
|
||||||
|
|
||||||
|
module Jobs
|
||||||
|
class RecoverPostUploads < Jobs::Onceoff
|
||||||
|
MIN_PERIOD = 30
|
||||||
|
MAX_PERIOD = 120
|
||||||
|
|
||||||
|
def execute_onceoff(args)
|
||||||
|
UploadRecovery.new.recover(Post.where(
|
||||||
|
"baked_at >= ?",
|
||||||
|
grace_period.days.ago
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
def grace_period
|
||||||
|
SiteSetting.purge_deleted_uploads_grace_period_days.clamp(
|
||||||
|
MIN_PERIOD,
|
||||||
|
MAX_PERIOD
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
17
spec/jobs/recover_post_uploads_spec.rb
Normal file
17
spec/jobs/recover_post_uploads_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Jobs::RecoverPostUploads do
|
||||||
|
describe '#grace_period' do
|
||||||
|
it 'should restrict the grace period to the right range' do
|
||||||
|
SiteSetting.purge_deleted_uploads_grace_period_days =
|
||||||
|
described_class::MIN_PERIOD - 1
|
||||||
|
|
||||||
|
expect(described_class.new.grace_period).to eq(30)
|
||||||
|
|
||||||
|
SiteSetting.purge_deleted_uploads_grace_period_days =
|
||||||
|
described_class::MAX_PERIOD + 1
|
||||||
|
|
||||||
|
expect(described_class.new.grace_period).to eq(120)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user