Skip to content

Commit

Permalink
Merge 63d9a9b into 63ec3b2
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 14, 2019
2 parents 63ec3b2 + 63d9a9b commit 37b63f9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 73 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ gem 'rake'
gem 'resque', '~> 1.27' # needs to match redis on VM
gem 'resque-lock'
gem 'resque-pool'
gem 'retries'
gem 'roo' # for processing spreadsheets
gem 'simple_form' # rails form that handles errors internally and easily integrated w/ Bootstrap
gem 'turbolinks' # improves speed of following links in web application
Expand All @@ -25,8 +24,7 @@ gem 'uglifier' # compressor for JavaScript assets
# Stanford gems
gem 'assembly-image', '~> 1.7'
gem 'assembly-objectfile', '~> 1.7'
gem 'dor-services', '~> 6.1'
gem 'dor-services-client', '~> 1.0'
gem 'dor-services', '~> 7.1'

group :test do
gem 'coveralls', require: false
Expand Down
33 changes: 14 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,22 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dor-rights-auth (1.3.0)
nokogiri
dor-services (6.8.0)
dor-services (7.1.0)
active-fedora (>= 8.7.0, < 9)
activesupport (>= 4.2.10, < 6.0.0)
activesupport (~> 5.1)
confstruct (~> 0.2.7)
deprecation (~> 0)
dor-rights-auth (~> 1.0, >= 1.2.0)
dor-services-client (~> 1.5)
dor-workflow-service (~> 2.11)
dor-workflow-client (~> 3.0)
druid-tools (>= 0.4.1)
equivalent-xml (~> 0.5, >= 0.5.1)
json (>= 1.8.1)
moab-versioning (~> 4.0)
net-sftp (~> 2.1)
nokogiri (~> 1.6)
om (~> 3.0)
rdf (~> 1.1, >= 1.1.7)
rest-client (>= 1.7, < 3)
retries
retries (~> 0.0.5)
rsolr (>= 1.0.3, < 3)
ruby-cache (~> 0.3.0)
rubydora (~> 2.1)
Expand All @@ -171,14 +169,14 @@ GEM
faraday (~> 0.15)
moab-versioning (~> 4.0)
nokogiri (~> 1.8)
dor-workflow-service (2.12.0)
dor-workflow-client (3.1.0)
activesupport (>= 3.2.1, < 6)
confstruct (>= 0.2.7, < 2)
deprecation
deprecation (~> 0)
faraday (~> 0.9, >= 0.9.2)
faraday_middleware
net-http-persistent (>= 2.9.4, < 4.a)
nokogiri (~> 1.6)
retries
druid-tools (1.0.0)
dry-configurable (0.8.2)
concurrent-ruby (~> 1.0)
Expand All @@ -201,7 +199,7 @@ GEM
dry-equalizer (~> 0.2)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 0.5, >= 0.5)
dry-validation (0.13.1)
dry-validation (0.13.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (~> 0.2, >= 0.2.1)
Expand All @@ -221,6 +219,8 @@ GEM
railties (>= 4.2.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
ffi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
Expand All @@ -237,9 +237,8 @@ GEM
concurrent-ruby (~> 1.0)
iso-639 (0.2.8)
jaro_winkler (1.5.2)
jbuilder (2.8.0)
jbuilder (2.9.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand Down Expand Up @@ -291,14 +290,12 @@ GEM
nom-xml (~> 1.0)
mono_logger (1.1.0)
multi_json (1.13.1)
multipart-post (2.1.0)
multipart-post (2.1.1)
mustermann (1.0.3)
net-http-persistent (3.0.1)
connection_pool (~> 2.2)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (5.2.0)
netrc (0.11.0)
nio4r (2.3.1)
Expand Down Expand Up @@ -438,7 +435,7 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
rubocop-rspec (1.32.0)
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-cache (0.3.0)
ruby-prof (0.17.0)
Expand Down Expand Up @@ -546,8 +543,7 @@ DEPENDENCIES
devise
devise-remote-user
dlss-capistrano (~> 3.1)
dor-services (~> 6.1)
dor-services-client (~> 1.0)
dor-services (~> 7.1)
equivalent-xml
factory_bot_rails
honeybadger (~> 3.1)
Expand All @@ -565,7 +561,6 @@ DEPENDENCIES
resque (~> 1.27)
resque-lock
resque-pool
retries
roo
rspec-rails (~> 3.7)
rubocop (~> 0.60.0)
Expand Down
20 changes: 1 addition & 19 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,35 +256,17 @@ def create_object_directories

# Call web service to add assemblyWF to the object in DOR.
def initialize_assembly_workflow
with_retries(max_tries: Dor::Config.dor_services.num_attempts, rescue: StandardError, handler: retry_handler('INITIALIZE_ASSEMBLY_WORKFLOW', method(:log))) do
api_client.object(druid.druid).workflow.create(wf_name: workflow_name)
end
Dor::Config.workflow.client.create_workflow_by_name(druid.druid, 'assemblyWF')
end

private

def api_client
@api_client ||= Dor::Services::Client.configure(url: Settings.DOR_SERVICES.URL,
username: Settings.DOR_SERVICES.USER,
password: Settings.DOR_SERVICES.PASS)
end

def workflow_name
'assemblyWF'
end

def technical_md_file
'technicalMetadata.xml'
end

def content_md_file
'contentMetadata.xml'
end

def retry_handler(method_name, _logger, params = {})
proc do |_exception, attempt_number, total_delay|
log(" ** #{method_name} FAILED **; with params of #{params.inspect}; and trying attempt #{attempt_number} of #{Dor::Config.dor_services.num_attempts}; delayed #{total_delay} seconds")
end
end
end
end
22 changes: 5 additions & 17 deletions config/initializers/dor_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
key_file Settings.dor_client_cert_key
end

# used to make dor-workflow-service call for a druid
# this is done at end of preassembly to kick off assembly
# TODO: use dor-workflow-service gem instead (see #194)
dor_services do
url Settings.DOR_SERVICES.URL
user Settings.DOR_SERVICES.USER
pass Settings.DOR_SERVICES.PASS
num_attempts Settings.dor_services_num_attempts
end

# used to look up object existence in DOR for discovery report
fedora do
# used to look up objects in DOR
url Settings.fedora_url
end
end

# TODO: use dor-workflow-service gem (see #194) instead of dor_services gem
# require 'dor-workflow-service'
# Dor::WorkflowService.configure(
# Settings.workflow_services_url,
# dor_services_url: Dor::Config.dor_services.url.gsub('/v1', '')
# )

workflow do
url Settings.workflow_url
end
end
8 changes: 2 additions & 6 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
dor_client_cert:
dor_client_cert_key:

# used to make dor-workflow-service call for a druid
# this is done at end of preassembly to kick off assembly
DOR_SERVICES:
URL: 'https://example.com/dor/v1'
dor_services_num_attempts: 1 # how many attempts to contact dor before throwing exception

# used to look up object existence in DOR for discovery report
# TODO: can we use dor-services-app instead? (see #226)
fedora_url: 'https://example.com/fedora'

workflow_url: 'https://workflow-env.stanford.edu/workflow'

# place where assemblyWF will look for object files
assembly_staging_dir: tmp/assembly

Expand Down
16 changes: 7 additions & 9 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,29 @@ def add_object_files(extension = 'tif')
end

describe '#initialize_assembly_workflow' do
subject(:start_workflow) { object.initialize_assembly_workflow }
before do
allow(object).to receive(:api_client).and_return(client)
allow(Dor::Config.workflow).to receive(:client).and_return(client)
allow(object).to receive(:druid).and_return(druid)
end

let(:client) { double }
let(:client) { instance_double(Dor::Workflow::Client, create_workflow_by_name: true) }
let(:service_url) { Settings.dor_services_url }

context 'when api client is successful' do
before do
allow(client).to receive_message_chain(:object, :workflow, :create)
end

it 'starts the assembly workflow' do
expect { object.initialize_assembly_workflow }.not_to raise_error
start_workflow
expect(client).to have_received(:create_workflow_by_name).with(druid.druid, 'assemblyWF')
end
end

context 'when the api client raises' do
before do
allow(client).to receive_message_chain(:object, :workflow, :create).and_raise(Dor::Services::Client::UnexpectedResponse)
allow(client).to receive(:create_workflow_by_name).and_raise(StandardError)
end

it 'raises an exception' do
expect { object.initialize_assembly_workflow }.to raise_error(Dor::Services::Client::UnexpectedResponse)
expect { start_workflow }.to raise_error(StandardError)
end
end
end
Expand Down

0 comments on commit 37b63f9

Please sign in to comment.