dor-services-client 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/dor/services/client/async_result.rb +55 -0
- data/lib/dor/services/client/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e698ec62b7dcceba6c335032d1ccf993c02bee7945cf5865c617c41bb00fa9e
|
4
|
+
data.tar.gz: 290957e4e5d96d0b44ffe4e9ccdfcf921947a49e809433139a979f5090176fe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd790382965aa0d8ead2bbcc73a699ddce26bdb7f623932753208ead6bb8484f36668e94bde69474cace9e40e376629ca5f38cd1dfad0d82294de791fcce6cdb
|
7
|
+
data.tar.gz: 3ca07906e522ce83ae5046147b752100d02914b2b1fb8ca511c1bbdb8b100dc11faafa9c6593b21b6128f429167acca1cc96e5f5425acbe3b05561e8bf7411a6
|
data/README.md
CHANGED
@@ -127,6 +127,25 @@ object_client.workspace.reset
|
|
127
127
|
object_client.embargo.update(embargo_date: date_string, requesting_user: username_string)
|
128
128
|
```
|
129
129
|
|
130
|
+
## Asynchonous results
|
131
|
+
|
132
|
+
Some operations are asynchronous and they return a `Location` header that displays the
|
133
|
+
result of the job. These jobs can be monitored by using `AsyncResult`.
|
134
|
+
|
135
|
+
```
|
136
|
+
background_result_url = virtual_objects_client.create(virtual_objects: [{ parent_id: '', child_ids: [''] }])
|
137
|
+
result = AsyncResult.new(url: background_result_url)
|
138
|
+
|
139
|
+
# Checks the result one time
|
140
|
+
result.complete?
|
141
|
+
|
142
|
+
# Poll until complete
|
143
|
+
result.wait_until_complete
|
144
|
+
|
145
|
+
result.errors
|
146
|
+
# => [{ 'druid:foo' => ['druid:bar'] }]
|
147
|
+
```
|
148
|
+
|
130
149
|
## Development
|
131
150
|
|
132
151
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module Dor
|
6
|
+
module Services
|
7
|
+
class Client
|
8
|
+
# A helper for monitoring asynchonous jobs
|
9
|
+
class AsyncResult
|
10
|
+
# @param [String] url the url of the background result
|
11
|
+
def initialize(url:)
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [Integer] seconds_between_requests (3) how many seconds between polling requests
|
16
|
+
# @param [Integer] timeout_in_seconds (180) timeout after this many seconds
|
17
|
+
# @return true if successful false if unsuccessful.
|
18
|
+
def wait_until_complete(seconds_between_requests: 3, timeout_in_seconds: 180)
|
19
|
+
poll_until_complete(seconds_between_requests, timeout_in_seconds)
|
20
|
+
errors.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
# Checks to see if the result is complete.
|
24
|
+
def complete?
|
25
|
+
@results = Dor::Services::Client.background_job_results.show(job_id: job_id_from(url: url))
|
26
|
+
@results[:status] == 'complete'
|
27
|
+
end
|
28
|
+
|
29
|
+
def errors
|
30
|
+
@results[:output][:errors]
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :url, :seconds_between_requests, :timeout_in_seconds
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def poll_until_complete(seconds_between_requests, timeout_in_seconds)
|
38
|
+
Timeout.timeout(timeout_in_seconds) do
|
39
|
+
loop do
|
40
|
+
break if complete?
|
41
|
+
|
42
|
+
sleep(seconds_between_requests)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue Timeout::Error
|
46
|
+
@results = { output: { errors: ["Not complete after #{timeout_in_seconds} seconds"] } }
|
47
|
+
end
|
48
|
+
|
49
|
+
def job_id_from(url:)
|
50
|
+
url.split('/').last
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-services-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- bin/setup
|
222
222
|
- dor-services-client.gemspec
|
223
223
|
- lib/dor/services/client.rb
|
224
|
+
- lib/dor/services/client/async_result.rb
|
224
225
|
- lib/dor/services/client/background_job_results.rb
|
225
226
|
- lib/dor/services/client/collections.rb
|
226
227
|
- lib/dor/services/client/embargo.rb
|