Skip to content

Commit

Permalink
Use native Sidekiq::Job for SCSB Full import
Browse files Browse the repository at this point in the history
- This is needed to use batches for this job
  • Loading branch information
maxkadel committed Dec 24, 2024
1 parent 5c29b2e commit 87e77d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/jobs/scsb_import_full_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ScsbImportFullJob < ApplicationJob
class ScsbImportFullJob
include Sidekiq::Job
def perform
delete_stale_files

Expand Down
9 changes: 6 additions & 3 deletions spec/jobs/scsb_import_full_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
require 'rails_helper'

RSpec.describe ScsbImportFullJob do
before do
Sidekiq::Testing.inline!
end
it 'creates an event' do
allow(Scsb::PartnerUpdates).to receive(:full)

expect { described_class.perform_now }.to change { Event.count }.by(1)
expect { described_class.perform_async }.to change { Event.count }.by(1)
event = Event.last

expect(event.start).not_to be nil
Expand All @@ -28,7 +31,7 @@
end

it 'removes stale files' do
expect { described_class.perform_now }.to change { Event.count }.by(1)
expect { described_class.perform_async }.to change { Event.count }.by(1)

expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'CUL_20210429_192300.zip'))).to be false
expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'NYPL_20210430_015000.zip'))).to be false
Expand All @@ -43,7 +46,7 @@
allow(FileUtils).to receive(:rm).with(Rails.root.join("tmp", "specs", "update_directory", 'NYPL_20210430_015000.zip').to_s).and_raise(Errno::ENOENT, 'No such file or directory @ apply2files')
end
it 'still deletes the other files that have not failed' do
described_class.perform_now
described_class.perform_async

expect(FileUtils).to have_received(:rm).exactly(4).times
expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'CUL_20210429_192300.zip'))).to be false
Expand Down

0 comments on commit 87e77d9

Please sign in to comment.