-
Notifications
You must be signed in to change notification settings - Fork 1
Add a route that automatically enqueues jobs to Resque #169
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Pushes workflow_step's into the Resque queue so that work can begin | ||
| # | ||
| # You may set the environment variable SETTINGS__ENABLE_QUEUING=false to | ||
| # prevent sending work to the Resque queue. | ||
| class WorkerQueue | ||
| # @param [ActiveRecord::Relation<WorkflowStep>] steps to enqueue | ||
| def self.enqueue_steps(steps) | ||
| return unless Settings.enable_queuing | ||
|
|
||
| steps.each do |step| | ||
| Resque.enqueue_to queue_name(step), job_name(step), step.druid | ||
| step.update(status: 'queued') | ||
| end | ||
| end | ||
|
|
||
| def self.job_name(step) | ||
| [ | ||
| 'Robots', | ||
| step.repository.camelcase + 'Repo', # 'Dor' conflicts with dor-services | ||
| step.workflow.sub('WF', '').camelcase, | ||
| step.process.tr('-', '_').camelcase | ||
| ].join('::') | ||
| end | ||
| private_class_method :job_name | ||
|
|
||
| def self.queue_name(step) | ||
| [ | ||
| step.repository, | ||
| step.workflow, | ||
| step.process, | ||
| 'default' | ||
| ].join('_') | ||
| end | ||
|
|
||
| private_class_method :queue_name | ||
| end |
This file contains hidden or 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,3 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Resque.redis = Settings.redis.url |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,8 +4,12 @@ dor_services: | |
| password: 'password' | ||
|
|
||
| enable_stomp: true | ||
| enable_queuing: true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you say more about what this change adds? |
||
|
|
||
| messaging: | ||
| uri: 'failover:(stomp+ssl://localhost:61612,stomp://remotehost:61613)' | ||
| # fedora_url is sent inside the message as the `entry.author.uri` field | ||
| fedora_url: 'https://dor-test.stanford.edu' | ||
|
|
||
| redis: | ||
| url: localhost:6379 | ||
This file contains hidden or 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,138 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe 'Start the next workflow step for an object', type: :request do | ||
| let(:client) { instance_double(Dor::Services::Client::Object, current_version: '1') } | ||
| let(:druid) { wf.druid } | ||
|
|
||
| before do | ||
| allow(Dor::Services::Client).to receive(:object).with(druid).and_return(client) | ||
| end | ||
|
|
||
| before do | ||
| allow(SendUpdateMessage).to receive(:publish) | ||
| end | ||
|
|
||
| context 'with XML indicating success' do | ||
| let(:process_xml) do | ||
| '<process name="descriptive-metadata" status="completed" elapsed="3" laneId="default" note="Yay"/>' | ||
| end | ||
|
|
||
| let(:wf) do | ||
| FactoryBot.create(:workflow_step, | ||
| workflow: 'accessionWF', | ||
| process: 'descriptive-metadata', | ||
| status: 'error', | ||
| error_msg: 'Bang!', | ||
| lifecycle: 'submitted') | ||
| end | ||
|
|
||
| let!(:next_step) do | ||
| FactoryBot.create(:workflow_step, | ||
| druid: wf.druid, | ||
| workflow: wf.workflow, | ||
| process: 'rights-metadata', | ||
| status: 'waiting') | ||
| end | ||
|
|
||
| before do | ||
| allow(Resque).to receive(:enqueue_to) | ||
| end | ||
|
|
||
| it 'enqueues a message to start the next step and sets the status to queued' do | ||
| post "/dor/objects/#{druid}/workflows/#{wf.workflow}/#{wf.process}/next", params: process_xml | ||
|
|
||
| wf.reload | ||
| expect(wf.status).to eq 'completed' | ||
| expect(wf.error_msg).to be_nil | ||
|
|
||
| expect(wf.lifecycle).to eq 'submitted' | ||
| json = JSON.parse(response.body) | ||
| expect(json['next_steps']).to eq [JSON.parse(next_step.reload.to_json)] | ||
| expect(SendUpdateMessage).to have_received(:publish).with(druid: wf.druid) | ||
| expect(Resque).to have_received(:enqueue_to) | ||
| .with('dor_accessionWF_rights-metadata_default', | ||
| 'Robots::DorRepo::Accession::RightsMetadata', | ||
| wf.druid) | ||
|
|
||
| expect(next_step.status).to eq 'queued' | ||
| end | ||
| end | ||
|
|
||
| context 'with XML indicating failure' do | ||
| let(:process_xml) do | ||
| '<process name="descriptive-metadata" status="error" elapsed="3" laneId="default" note="Yay"/>' | ||
| end | ||
|
|
||
| let(:wf) do | ||
| FactoryBot.create(:workflow_step, | ||
| workflow: 'accessionWF', | ||
| process: 'descriptive-metadata', | ||
| status: 'error', | ||
| error_msg: 'Bang!', | ||
| lifecycle: 'submitted') | ||
| end | ||
|
|
||
| let!(:next_step) do | ||
| FactoryBot.create(:workflow_step, | ||
| druid: wf.druid, | ||
| workflow: wf.workflow, | ||
| process: 'rights-metadata', | ||
| status: 'waiting') | ||
| end | ||
|
|
||
| before do | ||
| allow(Resque).to receive(:enqueue_to) | ||
| end | ||
|
|
||
| it "doesn't enqueue the next step " do | ||
| post "/dor/objects/#{druid}/workflows/#{wf.workflow}/#{wf.process}/next", params: process_xml | ||
|
|
||
| wf.reload | ||
| expect(wf.status).to eq 'error' | ||
| expect(wf.error_msg).to be_nil | ||
|
|
||
| expect(wf.lifecycle).to eq 'submitted' | ||
|
|
||
| expect(response.body).to eq '{"next_steps":[]}' | ||
| expect(SendUpdateMessage).to have_received(:publish).with(druid: wf.druid) | ||
| expect(Resque).not_to have_received(:enqueue_to) | ||
| end | ||
| end | ||
|
|
||
| context 'when the next step does not get enqueued' do | ||
| let(:process_xml) do | ||
| '<process name="sdr-ingest-transfer" status="completed" elapsed="3" laneId="default" note="Yay"/>' | ||
| end | ||
|
|
||
| let(:wf) do | ||
| FactoryBot.create(:workflow_step, | ||
| workflow: 'accessionWF', | ||
| process: 'sdr-ingest-transfer', | ||
| status: 'waiting') | ||
| end | ||
|
|
||
| let!(:next_step) do | ||
| FactoryBot.create(:workflow_step, | ||
| druid: wf.druid, | ||
| workflow: wf.workflow, | ||
| process: 'sdr-ingest-received', | ||
| status: 'waiting') | ||
| end | ||
|
|
||
| before do | ||
| allow(Resque).to receive(:enqueue_to) | ||
| end | ||
|
|
||
| it "doesn't enqueue the next step " do | ||
| post "/dor/objects/#{druid}/workflows/#{wf.workflow}/#{wf.process}/next", params: process_xml | ||
|
|
||
| wf.reload | ||
| expect(wf.status).to eq 'completed' | ||
| expect(response.body).to eq '{"next_steps":[]}' | ||
| expect(SendUpdateMessage).to have_received(:publish).with(druid: wf.druid) | ||
| expect(Resque).not_to have_received(:enqueue_to) | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR is looking good so far. I'm curious about mixing
postandputhere. Doessteps#nextfunction more like a create operation? The methods look similar to me.