Cleanup pending photos which were never posted with cronjob
Only delete photos older than a day, so we don't delete photos for posts which were uploaded 10 minutes ago and the author is still writing the post for it. closes #8041
This commit is contained in:
parent
397dbdbee8
commit
df4e79b842
4 changed files with 48 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
* Add cronjob to cleanup pending photos which were never posted [#8041](https://github.com/diaspora/diaspora/pull/8041)
|
||||||
|
|
||||||
# 0.7.12.0
|
# 0.7.12.0
|
||||||
|
|
||||||
|
|
|
||||||
11
app/workers/cleanup_pending_photos.rb
Normal file
11
app/workers/cleanup_pending_photos.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Workers
|
||||||
|
class CleanupPendingPhotos < Base
|
||||||
|
sidekiq_options queue: :low
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Photo.where(pending: true).where("created_at < ?", 1.day.ago).destroy_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -29,6 +29,11 @@ def default_job_config
|
||||||
"class": "Workers::CleanupOldExports"
|
"class": "Workers::CleanupOldExports"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
cleanup_pending_photos: {
|
||||||
|
"cron": "#{random_minute.call} #{random_hour.call} * * *",
|
||||||
|
"class": "Workers::CleanupPendingPhotos"
|
||||||
|
},
|
||||||
|
|
||||||
queue_users_for_removal: {
|
queue_users_for_removal: {
|
||||||
"cron": "#{random_minute.call} #{random_hour.call} * * *",
|
"cron": "#{random_minute.call} #{random_hour.call} * * *",
|
||||||
"class": "Workers::QueueUsersForRemoval"
|
"class": "Workers::QueueUsersForRemoval"
|
||||||
|
|
|
||||||
31
spec/workers/cleanup_pending_photos_spec.rb
Normal file
31
spec/workers/cleanup_pending_photos_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe Workers::CleanupPendingPhotos do
|
||||||
|
let!(:photo) { FactoryGirl.create(:photo, author: alice.person, pending: true) }
|
||||||
|
|
||||||
|
it "removes pending photos" do
|
||||||
|
Timecop.travel(25.hours) do
|
||||||
|
Workers::CleanupPendingPhotos.new.perform
|
||||||
|
expect(Photo).not_to exist(photo.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not remove pending photos newer than one day" do
|
||||||
|
Timecop.travel(1.hour) do
|
||||||
|
Workers::CleanupPendingPhotos.new.perform
|
||||||
|
expect(Photo).to exist(photo.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not remove posted photos" do
|
||||||
|
StatusMessageCreationService.new(alice).create(
|
||||||
|
status_message: {text: "Post with photo"},
|
||||||
|
public: true,
|
||||||
|
photos: [photo.id]
|
||||||
|
)
|
||||||
|
Timecop.travel(25.hours) do
|
||||||
|
Workers::CleanupPendingPhotos.new.perform
|
||||||
|
expect(Photo).to exist(photo.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue