Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exporter status #3203

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ AllCops:
- 'app/parsers/bulkrax/bagit_complex_parser.rb'
- 'app/views/bulkrax/**/*'
- 'app/parsers/bulkrax/parser_export_record_set.rb'
- 'app/jobs/bulkrax/export_work_job.rb'

Metrics/BlockLength:
ExcludedMethods: ['included']
Expand Down
40 changes: 40 additions & 0 deletions app/jobs/bulkrax/export_work_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module Bulkrax
class ExportWorkJob < ApplicationJob
queue_as :export

def perform(*args)
entry = Entry.find(args[0])
exporter_run = ExporterRun.find(args[1])
begin
entry.build
entry.save
rescue StandardError
# rubocop:disable Rails/SkipsModelValidations
ExporterRun.increment_counter(:failed_records, args[1])
ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
raise
else
if entry.failed?
ExporterRun.increment_counter(:failed_records, args[1])
ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
raise entry.reload.current_status.error_class.constantize
else
ExporterRun.increment_counter(:processed_records, args[1])
ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
end
# rubocop:enable Rails/SkipsModelValidations
end
return entry if exporter_run.reload.enqueued_records.positive?

if exporter_run.failed_records.positive?
exporter_run.exporter.set_status_info('Complete (with failures)')
else
exporter_run.exporter.set_status_info('Complete')
end

return entry
end
end
end