-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rake task to update state. datacite/datacite#491
- Loading branch information
Martin Fenner
committed
Sep 24, 2018
1 parent
68af844
commit c6655e3
Showing
3 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class UpdateStateJob < ActiveJob::Base | ||
queue_as :lupo_background | ||
|
||
def perform(doi_id, options={}) | ||
logger = Logger.new(STDOUT) | ||
doi = Doi.where(doi: doi_id).first | ||
|
||
if doi.blank? | ||
logger.info "[Update State] Error updating state for DOI " + doi_id + ": not found" | ||
elsif doi.update_attributes(aasm_state: options[:state]) | ||
logger.info "[Update State] Successfully update state for DOI " + doi_id | ||
else | ||
logger.info "[Update State] Error updating state for DOI " + doi_id + ": " + errors.inspect | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'rails_helper' | ||
|
||
describe UpdateStateJob, type: :job do | ||
let(:doi) { create(:doi) } | ||
subject(:job) { UpdateStateJob.perform_later(doi.doi) } | ||
|
||
it 'queues the job' do | ||
expect { job }.to have_enqueued_job(UpdateStateJob) | ||
.on_queue("test_lupo_background") | ||
end | ||
|
||
after do | ||
clear_enqueued_jobs | ||
clear_performed_jobs | ||
end | ||
end |