dor-workflow-service 1.7.8 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d5306f7d3d1f1953e514107f396d0825e0854a3
4
- data.tar.gz: 84b6a3c973490b1cdb5aad357a0688e47050229f
3
+ metadata.gz: abb7f9fafd6a57bbe2ce009a7f3d8bca21680383
4
+ data.tar.gz: 4c7ca111d9dbf464495a22eeb7a40bad80f8a805
5
5
  SHA512:
6
- metadata.gz: e804cc302c961ad241514d095152c0dff6554a55db0d59ede0772943558a00cbe13cd1a00b41c7cd49fc31f42b19b67f4274cd9ebd8e2cb998552860c581adf1
7
- data.tar.gz: e1f09e4836852064692aded4c5b337da4f374e68ed419fe4990d10b8d33e93183e0ee94f90a7a531484319086a7412627071530c19d65a37de899459fcc2cb49
6
+ metadata.gz: 008f69b8e8cf014a2d2490417b0812d34ef88bd731b5b9cbad822fec2938c6d4e5a9f7ef3bb3f78942a909b64ff625b8594f6f5f39a5edb689a7c603badc366e
7
+ data.tar.gz: 24ad2b473ff2507560897f0704c4c8813adb1b1092dccafea7eb49c565c3382ba936bf54991d4f226d19b59f42c49f2c1d018b732a6bd421877aa9c72da81103
@@ -4,9 +4,9 @@ notifications:
4
4
  email: false
5
5
 
6
6
  rvm:
7
+ - 1.9.3
8
+ - 2.0.0
7
9
  - 2.1.2
8
- - 2.2.7
9
- - 2.3.4
10
10
 
11
11
  gemfile:
12
12
  - gemfiles/rails3.gemfile
@@ -18,10 +18,12 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_dependency 'activesupport', '>= 3.2.1', '< 5'
21
- gem.add_dependency 'nokogiri', '~> 1.6'
21
+ gem.add_dependency 'nokogiri', '~> 1.6.0'
22
22
  gem.add_dependency 'rest-client', '~> 1.7'
23
23
  gem.add_dependency 'retries'
24
24
  gem.add_dependency 'confstruct', '>= 0.2.7', '< 2'
25
+ gem.add_dependency 'faraday', '~> 0.9.2'
26
+ gem.add_dependency 'net-http-persistent', '~> 2.9.4'
25
27
 
26
28
  gem.add_development_dependency 'rake'
27
29
  gem.add_development_dependency 'rspec', '~> 3.3'
@@ -3,6 +3,8 @@ require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
  require 'nokogiri'
5
5
  require 'retries'
6
+ require 'faraday'
7
+ require 'net/http/persistent'
6
8
 
7
9
  module Dor
8
10
 
@@ -22,6 +24,7 @@ module Dor
22
24
  @@logger = nil
23
25
  @@resource = nil
24
26
  @@dor_services_url = nil
27
+ @@http_conn = nil
25
28
 
26
29
  # From Workflow Service's admin/Process.java
27
30
  VALID_STATUS = %w{waiting completed error queued skipped hold}
@@ -467,6 +470,10 @@ module Dor
467
470
  @@logger.warn "[Attempt #{attempt_number}] #{exception.class}: #{exception.message}; #{total_delay} seconds elapsed."
468
471
  end
469
472
  @@resource = RestClient::Resource.new(url, params)
473
+ @@http_conn = Faraday.new(url: url) do |faraday|
474
+ faraday.response :logger if opts[:debug] # logs to STDOUT
475
+ faraday.adapter :net_http_persistent # use Keep-Alive connections
476
+ end
470
477
  end
471
478
 
472
479
 
@@ -519,7 +526,11 @@ module Dor
519
526
  def workflow_resource_method(uri_string, meth = 'get', payload = '', opts = {})
520
527
  with_retries(:max_tries => 2, :handler => @@handler, :rescue => workflow_service_exceptions_to_catch) do |attempt|
521
528
  @@logger.info "[Attempt #{attempt}] #{meth} #{workflow_resource.url}/#{uri_string}"
522
- if %w[get delete].include?(meth)
529
+ if meth == 'get'
530
+ fail NotImplementedError, "GET does not support extra headers: #{opts}" unless opts.length == 0
531
+ @@logger.debug "Persistent HTTP GET #{uri_string} (#{@@http_conn.inspect})"
532
+ @@http_conn.get(uri_string).body
533
+ elsif meth == 'delete'
523
534
  workflow_resource[uri_string].send(meth, opts)
524
535
  elsif opts.size == 0 # the right number of args allows existing test expect/with statements to continue working
525
536
  workflow_resource[uri_string].send(meth, payload)
@@ -1,7 +1,7 @@
1
1
  module Dor
2
2
  module Workflow
3
3
  module Service
4
- VERSION = '1.7.8'
4
+ VERSION = '1.8.0'
5
5
  end
6
6
  end
7
7
  end
@@ -28,14 +28,21 @@ describe Dor::WorkflowService do
28
28
  @repo = 'dor'
29
29
  @druid = 'druid:123'
30
30
  @mock_resource = double('mock_rest_client_resource')
31
- @mock_logger = double('Logger')
31
+ @mock_http_connection = double('mock_http_connection')
32
+ @mock_logger = double('Logger')
33
+
34
+ allow(@mock_logger).to receive(:info) # silence log output
35
+ allow(@mock_logger).to receive(:debug) # silence log output
36
+ allow(Dor::WorkflowService).to receive(:default_logger).and_return(@mock_logger)
37
+
32
38
  allow(@mock_resource).to receive(:[]).and_return(@mock_resource)
33
39
  allow(@mock_resource).to receive(:options).and_return( {} )
34
- allow(@mock_resource).to receive(:url).and_return( 'https://dortest.stanford.edu/workflow' )
35
- allow(@mock_logger).to receive(:info)
40
+ allow(@mock_resource).to receive(:url).and_return( 'https://localhost/workflow' )
41
+
42
+ allow(Faraday).to receive(:new).and_return(@mock_http_connection)
43
+
36
44
  allow(RestClient::Resource).to receive(:new).and_return(@mock_resource)
37
- allow(Dor::WorkflowService).to receive(:default_logger).and_return(@mock_logger)
38
- Dor::WorkflowService.configure 'https://dortest.stanford.edu/workflow'
45
+ Dor::WorkflowService.configure @mock_resource.url
39
46
  end
40
47
 
41
48
  describe '#create_workflow' do
@@ -121,20 +128,21 @@ describe Dor::WorkflowService do
121
128
 
122
129
  describe '#get_workflow_status' do
123
130
  it 'parses workflow xml and returns status as a string' do
124
- expect(@mock_resource).to receive(:get).and_return('<process name="registrar-approval" status="completed" />')
131
+ xml = '<process name="registrar-approval" status="completed" />'
132
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => xml)
125
133
  expect(Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval')).to eq('completed')
126
134
  end
127
135
  it 'should throw an exception if it fails for any reason' do
128
136
  ex = Exception.new('exception thrown')
129
- expect(@mock_resource).to receive(:get).and_raise(ex)
137
+ allow(@mock_http_connection).to receive(:get).and_raise(ex)
130
138
  expect{ Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval') }.to raise_error(Exception, 'exception thrown')
131
139
  end
132
140
  it 'should throw an exception if it cannot parse the response' do
133
- expect(@mock_resource).to receive(:get).and_return('something not xml')
141
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => 'something not xml')
134
142
  expect{ Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval') }.to raise_error(Exception, "Unable to parse response:\nsomething not xml")
135
143
  end
136
144
  it 'should return nil if the workflow/process combination doesnt exist' do
137
- expect(@mock_resource).to receive(:get).and_return('<process name="registrar-approval" status="completed" />')
145
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => '<process name="registrar-approval" status="completed" />')
138
146
  expect(Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'accessionWF', 'publish')).to be_nil
139
147
  end
140
148
  end
@@ -142,7 +150,7 @@ describe Dor::WorkflowService do
142
150
  describe '#get_workflow_xml' do
143
151
  it 'returns the xml for a given repository, druid, and workflow' do
144
152
  xml = '<workflow id="etdSubmitWF"><process name="registrar-approval" status="completed" /></workflow>'
145
- expect(@mock_resource).to receive(:get).and_return(xml)
153
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => xml)
146
154
  expect(Dor::WorkflowService.get_workflow_xml('dor', 'druid:123', 'etdSubmitWF')).to eq(xml)
147
155
  end
148
156
  end
@@ -156,17 +164,18 @@ describe Dor::WorkflowService do
156
164
  <milestone date="2010-06-15T16:08:58-0700">released</milestone>
157
165
  </lifecycle>
158
166
  EOXML
159
- expect(@mock_resource).to receive(:get).and_return(xml)
167
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => xml)
160
168
  expect(Dor::WorkflowService.get_lifecycle('dor', 'druid:123', 'released').beginning_of_day).to eq(Time.parse('2010-06-15T16:08:58-0700').beginning_of_day)
161
169
  end
162
170
 
163
171
  it "returns nil if the milestone hasn't been reached yet" do
164
- expect(@mock_resource).to receive(:get).and_return('<lifecycle/>')
172
+ xml = '<lifecycle/>'
173
+ allow(@mock_http_connection).to receive(:get).and_return(double Faraday::Response, :body => xml)
165
174
  expect(Dor::WorkflowService.get_lifecycle('dor', 'druid:abc', 'inprocess')).to be_nil
166
175
  end
167
176
  end
168
177
 
169
- describe '#get_objects_for_workstep' do
178
+ context '#get_objects_for_workstep' do
170
179
  before :each do
171
180
  @repository = 'dor'
172
181
  @workflow = 'googleScannedBookWF'
@@ -174,19 +183,19 @@ describe Dor::WorkflowService do
174
183
  @waiting = 'process-content'
175
184
  end
176
185
 
177
- context 'a query with one step completed and one waiting' do
186
+ describe 'a query with one step completed and one waiting' do
178
187
  it 'creates the URI string with only the one completed step' do
179
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default")
180
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
188
+ xml = %{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>}
189
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default").and_return(double Faraday::Response, :body => xml)
181
190
  expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
182
191
  end
183
192
  end
184
193
 
185
- context 'a query with TWO steps completed and one waiting' do
194
+ describe 'a query with TWO steps completed and one waiting' do
186
195
  it 'creates the URI string with the two completed steps correctly' do
187
196
  second_completed = 'google-convert'
188
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default")
189
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
197
+ xml = %{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>}
198
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default").and_return(double Faraday::Response, :body => xml)
190
199
  expect(Dor::WorkflowService.get_objects_for_workstep([@completed, second_completed], @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
191
200
  end
192
201
  end
@@ -201,8 +210,8 @@ describe Dor::WorkflowService do
201
210
  it 'creates the URI string with the two completed steps across repositories correctly' do
202
211
  qualified_completed2 = "sdr:sdrIngestWF:complete-deposit"
203
212
  qualified_completed3 = "sdr:sdrIngestWF:ingest-transfer"
204
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}")
205
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
213
+ xml = %{<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>}
214
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}").and_return(double Faraday::Response, :body => xml)
206
215
  args = [[@qualified_completed, qualified_completed2, qualified_completed3], @qualified_waiting]
207
216
  args << laneid if laneid != 'default'
208
217
  expect(Dor::WorkflowService.get_objects_for_workstep(*args)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
@@ -220,20 +229,20 @@ describe Dor::WorkflowService do
220
229
  end
221
230
  end
222
231
 
223
- describe 'URI string creation' do
232
+ context 'URI string creation' do
224
233
  before :each do
225
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/></objects>})
234
+ @xml = %{<objects count="1"><object id="druid:ab123de4567"/></objects>}
226
235
  end
227
236
  it 'with only one completed step passed in as a String' do
228
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&lane-id=default")
237
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&lane-id=default").and_return(double Faraday::Response, :body => @xml)
229
238
  expect(Dor::WorkflowService.get_objects_for_workstep(@qualified_completed, @qualified_waiting)).to eq(['druid:ab123de4567'])
230
239
  end
231
240
  it 'without any completed steps, only waiting' do
232
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=default")
241
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=default").and_return(double Faraday::Response, :body => @xml)
233
242
  expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting)).to eq(['druid:ab123de4567'])
234
243
  end
235
244
  it 'same but with lane_id' do
236
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=lane1")
245
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=lane1").and_return(double Faraday::Response, :body => @xml)
237
246
  expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting, 'lane1')).to eq([ 'druid:ab123de4567' ])
238
247
  end
239
248
  end
@@ -246,8 +255,8 @@ describe Dor::WorkflowService do
246
255
  workflow = 'googleScannedBookWF'
247
256
  completed = 'google-download'
248
257
  waiting = 'process-content'
249
- expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{repository}:#{workflow}:#{waiting}&completed=#{repository}:#{workflow}:#{completed}&lane-id=default")
250
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="0"/>})
258
+ xml = %{<objects count="0"/>}
259
+ allow(@mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{repository}:#{workflow}:#{waiting}&completed=#{repository}:#{workflow}:#{completed}&lane-id=default").and_return(double Faraday::Response, :body => xml)
251
260
  expect(Dor::WorkflowService.get_objects_for_workstep(completed, waiting, 'default', :default_repository => repository, :default_workflow => workflow)).to eq([])
252
261
  end
253
262
  end
@@ -310,8 +319,7 @@ describe Dor::WorkflowService do
310
319
  <workflow laneId="lane2" note="annotation" lifecycle="in-process" errorText="stacktrace" errorMessage="NullPointerException" elapsed="1.173" repository="dor" attempts="0" datetime="2008-11-15T13:30:00-0800" status="waiting" process="jp2-create" name="assemblyWF" druid="dr:456"/>
311
320
  </workflows>
312
321
  XML
313
- expect(@mock_resource).to receive(:[]).with('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100')
314
- expect(@mock_resource).to receive(:get).and_return(xml)
322
+ allow(@mock_http_connection).to receive(:get).with('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100').and_return(double Faraday::Response, :body => xml)
315
323
  ah = Dor::WorkflowService.get_stale_queued_workflows 'dor', :hours_ago => 24, :limit => 100
316
324
  expected = [
317
325
  { :workflow => 'accessionWF', :step => 'content-metadata', :druid => 'dr:123', :lane_id => 'lane1' },
@@ -323,8 +331,8 @@ describe Dor::WorkflowService do
323
331
 
324
332
  describe '.count_stale_queued_workflows' do
325
333
  it 'returns the number of queued workflow steps' do
326
- expect(@mock_resource).to receive(:[]).with('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true')
327
- expect(@mock_resource).to receive(:get).and_return(%{<objects count="10"/>})
334
+ xml = %{<objects count="10"/>}
335
+ allow(@mock_http_connection).to receive(:get).with('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true').and_return(double Faraday::Response, :body => xml)
328
336
  expect(Dor::WorkflowService.count_stale_queued_workflows('dor', :hours_ago => 48)).to eq(10)
329
337
  end
330
338
  end
@@ -337,8 +345,7 @@ describe Dor::WorkflowService do
337
345
  <lane id="lane2"/>
338
346
  </lanes>
339
347
  XML
340
- expect(@mock_resource).to receive(:[]).with('workflow_queue/lane_ids?step=dor:accessionWF:shelve')
341
- expect(@mock_resource).to receive(:get).and_return(xml)
348
+ allow(@mock_http_connection).to receive(:get).with('workflow_queue/lane_ids?step=dor:accessionWF:shelve').and_return(double Faraday::Response, :body => xml)
342
349
  expect(Dor::WorkflowService.get_lane_ids('dor', 'accessionWF', 'shelve')).to eq(%w(lane1 lane2))
343
350
  end
344
351
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-workflow-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.8
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willy Mene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-18 00:00:00.000000000 Z
12
+ date: 2015-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: 1.6.0
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: 1.6.0
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rest-client
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +93,34 @@ dependencies:
93
93
  - - "<"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '2'
96
+ - !ruby/object:Gem::Dependency
97
+ name: faraday
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.2
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: net-http-persistent
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 2.9.4
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 2.9.4
96
124
  - !ruby/object:Gem::Dependency
97
125
  name: rake
98
126
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
238
  version: '0'
211
239
  requirements: []
212
240
  rubyforge_project:
213
- rubygems_version: 2.6.12
241
+ rubygems_version: 2.4.8
214
242
  signing_key:
215
243
  specification_version: 4
216
244
  summary: Provides convenience methods to work with the DOR Workflow Service