sdr-client 2.13.1 → 2.13.2
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/Gemfile.lock +1 -1
- data/lib/sdr_client/redesigned_client/cli/credentials.rb +5 -5
- data/lib/sdr_client/redesigned_client/cli/update.rb +2 -2
- data/lib/sdr_client/redesigned_client/cli.rb +14 -5
- data/lib/sdr_client/redesigned_client/job_status.rb +19 -17
- data/lib/sdr_client/redesigned_client/metadata.rb +1 -0
- data/lib/sdr_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ae047ce917b1e8806379dd4aa57282c69af3eb1a756ffc1a2c01e67e8eef76
|
4
|
+
data.tar.gz: 475b3e52ee610abfd063f512fcdbbe9c2cc35a52ac6ab368a72e81925a132e19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df78e5244f588d1fe88a96d564e77e2611cb2dc503c9b8300ec06cc1fbffdb79ec4332502e38b6aa87ee5b1f287ca4134f7d4c6c8c6e55061b30a60708ec406a
|
7
|
+
data.tar.gz: 171f539702caf45adefa8037f788e9dc8de530a11d35fd0a6c6b1bbbb9a7bb017bf3997e05d6c2e8097a07b15c5af1b073b93c70aa9001be69ea6138ef9d74a4
|
data/Gemfile.lock
CHANGED
@@ -9,25 +9,25 @@ module SdrClient
|
|
9
9
|
def self.write(body)
|
10
10
|
token = JSON.parse(body).fetch('token')
|
11
11
|
FileUtils.mkdir_p(credentials_path, mode: 0o700)
|
12
|
-
File.atomic_write(credentials_file) { |file| file.write(token) }
|
13
|
-
File.chmod(0o600, credentials_file)
|
12
|
+
::File.atomic_write(credentials_file) { |file| file.write(token) }
|
13
|
+
::File.chmod(0o600, credentials_file)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.read
|
17
17
|
return unless ::File.exist?(credentials_file)
|
18
18
|
|
19
|
-
creds = File.read(credentials_file, chomp: true)
|
19
|
+
creds = ::File.read(credentials_file, chomp: true)
|
20
20
|
return if creds.nil?
|
21
21
|
|
22
22
|
creds
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.credentials_path
|
26
|
-
@credentials_path ||= File.join(Dir.home, '.sdr')
|
26
|
+
@credentials_path ||= ::File.join(Dir.home, '.sdr')
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.credentials_file
|
30
|
-
File.join(credentials_path, 'credentials')
|
30
|
+
::File.join(credentials_path, 'credentials')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -46,7 +46,7 @@ module SdrClient
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def cocina_hash_from_file
|
49
|
-
@cocina_hash_from_file ||= JSON.parse(File.read(options[:cocina_file]), symbolize_names: true)
|
49
|
+
@cocina_hash_from_file ||= JSON.parse(::File.read(options[:cocina_file]), symbolize_names: true)
|
50
50
|
end
|
51
51
|
|
52
52
|
def cocina_hash_from_pipe
|
@@ -65,7 +65,7 @@ module SdrClient
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def update_cocina_from_file(cocina_object)
|
68
|
-
if
|
68
|
+
if !::File.file?(options[:cocina_file]) || !::File.readable?(options[:cocina_file])
|
69
69
|
raise "File not found: #{options[:cocina_file]}"
|
70
70
|
end
|
71
71
|
|
@@ -64,17 +64,26 @@ module SdrClient
|
|
64
64
|
validate_druid!(druid)
|
65
65
|
# Make sure client is configured
|
66
66
|
client
|
67
|
-
job_id =
|
67
|
+
job_id = Update.run(druid, **options)
|
68
68
|
if options[:skip_polling]
|
69
69
|
say "job ID #{job_id} queued (not polling because `-s` flag was supplied)"
|
70
70
|
return
|
71
71
|
end
|
72
72
|
|
73
|
+
# the extra args to `say` prevent appending a newline
|
74
|
+
say('SDR is processing your request.', nil, false)
|
75
|
+
|
73
76
|
job_status = client.job_status(job_id: job_id)
|
74
|
-
|
75
|
-
|
77
|
+
job_status.wait_until_complete { say('.', nil, false) }
|
78
|
+
|
79
|
+
if job_status.complete?
|
80
|
+
if job_status.errors
|
81
|
+
say_error " errored! #{job_status.errors}"
|
82
|
+
else
|
83
|
+
say " success! (druid: #{job_status.druid})"
|
84
|
+
end
|
76
85
|
else
|
77
|
-
say_error "
|
86
|
+
say_error " job #{job_id} did not complete\n#{job_status.result.inspect}"
|
78
87
|
end
|
79
88
|
end
|
80
89
|
|
@@ -143,7 +152,7 @@ module SdrClient
|
|
143
152
|
sleep 0.5
|
144
153
|
token_string = ask('Paste token here:')
|
145
154
|
expiry = JSON.parse(token_string)['exp']
|
146
|
-
|
155
|
+
Credentials.write(token_string)
|
147
156
|
say "You are now authenticated for #{options[:url]} until #{expiry}"
|
148
157
|
token_string
|
149
158
|
end
|
@@ -6,6 +6,8 @@ module SdrClient
|
|
6
6
|
class RedesignedClient
|
7
7
|
# Wraps operations waiting for results from jobs
|
8
8
|
class JobStatus
|
9
|
+
attr_reader :result
|
10
|
+
|
9
11
|
def initialize(job_id:)
|
10
12
|
@job_id = job_id
|
11
13
|
@result = {
|
@@ -35,11 +37,26 @@ module SdrClient
|
|
35
37
|
# @param [Integer] timeout_in_secs (180) timeout after this many secs
|
36
38
|
# @param [Float] backoff_factor (2.0) how quickly to backoff. This should be > 1.0 and probably ought to be <= 2.0
|
37
39
|
# @return [Boolean] true if successful false if unsuccessful.
|
38
|
-
def wait_until_complete(secs_between_requests: 3.0,
|
40
|
+
def wait_until_complete(secs_between_requests: 3.0, # rubocop:disable Metrics/MethodLength
|
39
41
|
timeout_in_secs: 180,
|
40
42
|
backoff_factor: 2.0,
|
41
43
|
max_secs_between_requests: 60)
|
42
|
-
|
44
|
+
begin
|
45
|
+
Timeout.timeout(timeout_in_secs) do
|
46
|
+
loop do
|
47
|
+
break if complete?
|
48
|
+
|
49
|
+
yield if block_given?
|
50
|
+
|
51
|
+
sleep(secs_between_requests)
|
52
|
+
# Exponential backoff, limited to max_secs_between_requests
|
53
|
+
secs_between_requests = [secs_between_requests * backoff_factor, max_secs_between_requests].min
|
54
|
+
end
|
55
|
+
end
|
56
|
+
rescue Timeout::Error
|
57
|
+
@result[:output][:errors] = ["Not complete after #{timeout_in_secs} seconds"]
|
58
|
+
end
|
59
|
+
|
43
60
|
errors.nil?
|
44
61
|
end
|
45
62
|
|
@@ -54,21 +71,6 @@ module SdrClient
|
|
54
71
|
def path
|
55
72
|
"/v1/background_job_results/#{job_id}"
|
56
73
|
end
|
57
|
-
|
58
|
-
def poll_until_complete(secs_between_requests, timeout_in_secs, backoff_factor, max_secs_between_requests)
|
59
|
-
interval = secs_between_requests
|
60
|
-
Timeout.timeout(timeout_in_secs) do
|
61
|
-
loop do
|
62
|
-
break if complete?
|
63
|
-
|
64
|
-
sleep(interval)
|
65
|
-
# Exponential backoff, limited to max_secs_between_requests
|
66
|
-
interval = [interval * backoff_factor, max_secs_between_requests].min
|
67
|
-
end
|
68
|
-
end
|
69
|
-
rescue Timeout::Error
|
70
|
-
@result[:output][:errors] = ["Not complete after #{timeout_in_secs} seconds"]
|
71
|
-
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
data/lib/sdr_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdr-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.13.
|
4
|
+
version: 2.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|