Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
SARAALERT-1480: Resolve ActiveJob::DeserializationError Download not …
Browse files Browse the repository at this point in the history
…found error (#1076)

This error appears when the Export Retry time is set lower than the Download Destroy Wait time. This configuration allows a User to perform another export before the DownloadsDestroyJob is run, causing the DeserializationError. When the User performs another export, the previous exports of the same type are destroyed. This causes the DeserializationError at most 45 minutes later.

As before, even if the Download is not found for a different reason, it will be destroyed by the PurgeJob and not lingering in object storage.

* Convert the Worker's perform call to use the Download ID instead of object so that a Download#exists? check can be performed before attempting to destroy.
  • Loading branch information
Bialogs authored and tstrass committed Sep 27, 2021
1 parent 734b98d commit 57130d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/active_storage/blobs/proxy_controller.rb
Expand Up @@ -45,7 +45,7 @@ def authorize_user!
end

def queue_destroy_download(download)
DestroyDownloadsJob.set(wait_until: ADMIN_OPTIONS['download_destroy_wait_time'].to_i.minute.from_now).perform_later(download)
DestroyDownloadsJob.set(wait_until: ADMIN_OPTIONS['download_destroy_wait_time'].to_i.minute.from_now).perform_later(download.id)
download.update(marked_for_deletion: true)
end
end
4 changes: 2 additions & 2 deletions app/jobs/destroy_downloads_job.rb
Expand Up @@ -4,7 +4,7 @@
class DestroyDownloadsJob < ApplicationJob
queue_as :exports

def perform(download)
download.destroy
def perform(download_id)
Download.find(download_id).destroy if Download.exists?(download_id)
end
end
17 changes: 17 additions & 0 deletions test/jobs/destroy_downloads_job_test.rb
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'test_case'

class DestroyDownloadsJobTest < ActiveSupport::TestCase
test 'download exists' do
assert(DestroyDownloadsJob.perform_now(create(:download).id))
end

# When performing another export of the same type, all existing downloads of that type
# will be deleted before the job runs. It should not raise in this case.
test 'download does not exist' do
assert_nothing_raised do
DestroyDownloadsJob.perform_now(0)
end
end
end

0 comments on commit 57130d4

Please sign in to comment.