Skip to content

Commit

Permalink
Merge branch 'master' into VI-850_mpi_flag_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bramleyjl authored Dec 12, 2024
2 parents fd96757 + 9c90a52 commit d09f83a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions modules/vba_documents/app/sidekiq/vba_documents/upload_remover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ class UploadRemover
def perform
return unless Settings.vba_documents.s3.enabled

rows = VBADocuments::UploadSubmission.select(:id, :guid, :status, :s3_deleted, :created_at)
.where(REMOVAL_QUERY, EXPIRATION_TIME.ago)
exp_time = EXPIRATION_TIME.ago

rows.find_in_batches do |batch|
VBADocuments::UploadSubmission.transaction do
batch.each do |upload|
Rails.logger.info("VBADocuments: Cleaning up s3: #{upload.inspect}")
loop do
us_guids = VBADocuments::UploadSubmission.where(REMOVAL_QUERY, exp_time).select(:guid).limit(25).pluck(:guid)
break if us_guids.empty?

store.delete(upload.guid) if store.object(upload.guid).exists?
end

# rubocop:disable Rails/SkipsModelValidations
VBADocuments::UploadSubmission.where(id: batch.pluck(:id)).update_all(s3_deleted: true)
# rubocop:enable Rails/SkipsModelValidations
us_guids.each do |us_guid|
Rails.logger.info("VBADocuments: Cleaning up s3: #{us_guid}")
store.delete(us_guid)
end

# rubocop:disable Rails/SkipsModelValidations
VBADocuments::UploadSubmission.where(guid: us_guids).update_all(s3_deleted: true)
# rubocop:enable Rails/SkipsModelValidations
end
end

Expand Down
2 changes: 1 addition & 1 deletion modules/vba_documents/spec/sidekiq/upload_remover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
allow(@objstore).to receive(:object).with(upload_old.guid).and_return(s3_object_old)
allow(s3_object_old).to receive(:exists?).and_return(true)
expect(@objstore).to receive(:delete).with(upload_old.guid)
expect(@objstore).not_to receive(:delete).with(upload_manually_removed.guid)
expect(@objstore).to receive(:delete).with(upload_manually_removed.guid)
described_class.new.perform
upload_old.reload
expect(upload_old.s3_deleted).to be_truthy
Expand Down

0 comments on commit d09f83a

Please sign in to comment.