Skip to content

Commit

Permalink
replace delayed extension with job
Browse files Browse the repository at this point in the history
- Delayed extensions has been disabled since sidekiq 5, and removed from 7
sidekiq/sidekiq#5076
So I replaced it with a new job.

- I also called it a job instead of worker as per Sidekiq's documentation
https://github.com/sidekiq/sidekiq/wiki/Best-Practices#4-use-precise-terminology
https://stackoverflow.com/questions/76095172/sidekiq-worker-vs-job
  • Loading branch information
vasconsaurus committed Nov 23, 2023
1 parent 812c731 commit 1f54091
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions app/models/concerns/media_archive_org_archiver.rb
Expand Up @@ -24,10 +24,8 @@ def send_to_archive_org(url, key_id, _supported = nil)
response = http.request(request)
Rails.logger.info level: 'INFO', message: '[archive_org] Sent URL to archive', url: url, code: response.code, response: response.message
body = JSON.parse(response.body)
job_id = body[job_id]
if job_id
# Media.delay_for(2.minutes).get_archive_org_status(job_id, url, key_id)
ArchiverStatusWorker.perform_in(2.minutes, job_id, url, key_id)
if body['job_id']
ArchiverStatusJob.perform_in(2.minutes, body['job_id'], url, key_id)
else
data = snapshot_data.to_h.merge({ error: { message: "(#{body['status_ext']}) #{body['message']}", code: Lapis::ErrorCodes::const_get('ARCHIVER_ERROR') }})
Media.notify_webhook_and_update_cache('archive_org', url, data, key_id)
Expand Down Expand Up @@ -65,7 +63,7 @@ def get_archive_org_status(job_id, url, key_id)
response = http.request(request)
body = JSON.parse(response.body)
if body['status'] == 'success'
location = "https://web.archive.org/web/#{body['timestamp']}/#{url}"
location = "https://web.archive.org/web/#{body['timestamp']}/#{url}"
data = { location: location }
Media.notify_webhook_and_update_cache('archive_org', url, data, key_id)
else
Expand Down
7 changes: 7 additions & 0 deletions app/sidekiq/archiver_status_job.rb
@@ -0,0 +1,7 @@
class ArchiverStatusJob
include Sidekiq::Job

def perform(job_id, url, key_id)
Media.get_archive_org_status(job_id, url, key_id)
end
end
7 changes: 0 additions & 7 deletions app/workers/archiver_status_worker.rb

This file was deleted.

0 comments on commit 1f54091

Please sign in to comment.