parent
497c647983
commit
d4e5d13a8f
3 changed files with 78 additions and 0 deletions
21
app/workers/cleanup_old_exports.rb
Normal file
21
app/workers/cleanup_old_exports.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# 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"
|
||||
|
|
|
|||
53
spec/workers/cleanup_old_exports_spec.rb
Normal file
53
spec/workers/cleanup_old_exports_spec.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# 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
|
||||
Loading…
Reference in a new issue