Commit d4e5d13a authored by Janakas's avatar Janakas Committed by Dennis Schubert

Remove old export archives after 2 weeks

Fixes #5727
parent 497c6479
# frozen_string_literal: true
module Workers
class CleanupOldExports < Base
sidekiq_options queue: :low
def perform
User.where("exported_at < ?", 14.days.ago).each do |user|
user.remove_export = true
user.exported_at = nil
user.save
end
User.where("exported_photos_at < ?", 14.days.ago).each do |user|
user.remove_exported_photos_file = true
user.exported_photos_at = nil
user.save
end
end
end
end
......@@ -17,3 +17,7 @@ recheck_scheduled_pods:
check_birthday:
cron: "0 0 * * *"
class: "Workers::CheckBirthday"
cleanup_old_exports:
cron: "0 0 * * *"
class: "Workers::CleanupOldExports"
# frozen_string_literal: true
describe Workers::CleanupOldExports do
let(:user) { FactoryGirl.create(:user) }
context "with profile data" do
before do
user.perform_export!
end
it "removes old archives" do
Timecop.travel(Time.zone.today + 15.days) do
Workers::CleanupOldExports.new.perform
user.reload
expect(user.export).not_to be_present
expect(user.exported_at).to be_nil
end
end
it "does not remove new archives" do
Timecop.travel(Time.zone.today + 1.day) do
Workers::CleanupOldExports.new.perform
user.reload
expect(user.export).to be_present
expect(user.exported_at).to be_present
end
end
end
context "with photos" do
before do
user.perform_export_photos!
end
it "removes old archives" do
Timecop.travel(Time.zone.today + 15.days) do
Workers::CleanupOldExports.new.perform
user.reload
expect(user.exported_photos_file).not_to be_present
expect(user.exported_photos_at).to be_nil
end
end
it "does not remove new archives" do
Timecop.travel(Time.zone.today + 1.day) do
Workers::CleanupOldExports.new.perform
user.reload
expect(user.exported_photos_file).to be_present
expect(user.exported_photos_at).to be_present
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment