eco-helpers 3.0.17 → 3.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +65 -0
- data/lib/eco/api/session/batch/launcher/retry.rb +3 -3
- data/lib/eco/api/session/batch/launcher.rb +42 -37
- data/lib/eco/version.rb +1 -1
- metadata +7 -8
- data/lib/eco/api/session/batch/launcher/mode.rb +0 -23
- data/lib/eco/api/session/batch/launcher/size.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c28bbf13f50c0f3f895c40c0ad8532d13233e0e2b81faea474bbeb0a1c2308
|
4
|
+
data.tar.gz: e13091192acd044b667cd20ebe7bcaf5c17da30c1ef83266fefa9ffa90fb8348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02fe482f0c75e0926fe147e1ab3f4b0a0d1b826990bae3ad8ea97fb0aa53a800e1d208fb62e209877c0594b4f32792096967ec1f0528be8c81c3cd8c404c5131
|
7
|
+
data.tar.gz: 4f9c12554b25c81243eac348f106392a092853c87204922d25cd1f25d287abcc23461df2b0a6a19b3dd3e4624f625e49ce5920ed04000ab6641f26312a38cb0f
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,13 @@ All notable changes to this project will be documented in this file.
|
|
8
8
|
|
9
9
|
### Changed
|
10
10
|
|
11
|
+
- upgrade `ecoportal-api` gem
|
12
|
+
- upgrade `ecoportal-api-v2` gem
|
13
|
+
- `Eco::API::Session::Batch#launch_batch`
|
14
|
+
- **removed** `per_page` parameter
|
15
|
+
- **added** auto-swap endpoint from `job` to `batch` on TimeOut errors.
|
16
|
+
- **retries** also on `Ecoportal::API::Errors::StartTimeOut`
|
17
|
+
|
11
18
|
### Fixed
|
12
19
|
|
13
20
|
## [3.0.17] - 2024-10-18
|
data/eco-helpers.gemspec
CHANGED
@@ -40,9 +40,9 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency 'bcrypt_pbkdf', '~> 1.0'
|
41
41
|
spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
|
42
42
|
spec.add_dependency 'dotenv', '~> 3'
|
43
|
-
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.
|
43
|
+
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.6'
|
44
44
|
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.2'
|
45
|
-
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.
|
45
|
+
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.11'
|
46
46
|
spec.add_dependency 'ed25519', '~> 1.2'
|
47
47
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
48
48
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
module Launcher
|
6
|
+
module ModeSize
|
7
|
+
include Eco::API::Session::Batch::Launcher::Options
|
8
|
+
|
9
|
+
DEFAULT_BATCH_SIZE = 50
|
10
|
+
DEFAULT_JOB_SIZE = 100
|
11
|
+
|
12
|
+
def batch_size(opts = options)
|
13
|
+
return job_mode_size if job_mode?(opts)
|
14
|
+
|
15
|
+
batch_mode_size
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# Swaps to batch endpoint on specific errors
|
21
|
+
def batch_mode_on(*error_types, options: self.options, allow_job_mode: true, &block)
|
22
|
+
in_job_mode = allow_job_mode && job_mode?(options)
|
23
|
+
|
24
|
+
yield(in_job_mode, batch_size(options))
|
25
|
+
rescue *error_types
|
26
|
+
raise unless in_job_mode
|
27
|
+
|
28
|
+
yield(false , batch_mode_size)
|
29
|
+
end
|
30
|
+
|
31
|
+
# MODE
|
32
|
+
|
33
|
+
# @return [Symbol] the batch mode to run
|
34
|
+
def batch_mode(opts = options)
|
35
|
+
opts.dig(:workflow, :batch, :mode) || :batch
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Boolean] are we running in `:job` mode?
|
39
|
+
def job_mode?(opts = options)
|
40
|
+
batch_mode(opts) == :job
|
41
|
+
end
|
42
|
+
|
43
|
+
# SIZE
|
44
|
+
|
45
|
+
def job_mode_size
|
46
|
+
options.dig(:workflow, :batch, :job, :size).then do |size|
|
47
|
+
next self.class::DEFAULT_JOB_SIZE unless size
|
48
|
+
|
49
|
+
size
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def batch_mode_size
|
54
|
+
options.dig(:workflow, :batch, :size).then do |size|
|
55
|
+
next self.class::DEFAULT_BATCH_SIZE unless size
|
56
|
+
|
57
|
+
[size, 100].min
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -16,9 +16,9 @@ module Eco
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def offer_retry_on(
|
19
|
+
def offer_retry_on(*error_types, retries_left: 3, &block)
|
20
20
|
yield
|
21
|
-
rescue
|
21
|
+
rescue *error_types => err
|
22
22
|
raise err.class, err.message, cause: nil unless retries_left.positive?
|
23
23
|
|
24
24
|
explanation = "#{err}\n"
|
@@ -29,7 +29,7 @@ module Eco
|
|
29
29
|
raise unless response.upcase.start_with?("Y")
|
30
30
|
|
31
31
|
puts "\nOkay... let's retry!"
|
32
|
-
offer_retry_on(
|
32
|
+
offer_retry_on(*error_types, retries_left: retries_left - 1, &block)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative 'launcher/valid_methods'
|
2
2
|
require_relative 'launcher/options'
|
3
|
-
require_relative 'launcher/
|
4
|
-
require_relative 'launcher/size'
|
3
|
+
require_relative 'launcher/mode_size'
|
5
4
|
require_relative 'launcher/benchmarking'
|
6
5
|
require_relative 'launcher/status_handling'
|
7
6
|
require_relative 'launcher/retry'
|
@@ -24,12 +23,17 @@ module Eco
|
|
24
23
|
end
|
25
24
|
|
26
25
|
include Options
|
27
|
-
include
|
28
|
-
include Size
|
26
|
+
include ModeSize
|
29
27
|
include Benchmarking
|
30
28
|
include StatusHandling
|
31
29
|
include Retry
|
32
30
|
|
31
|
+
TIMEOUT_RETRIES = 2
|
32
|
+
RETRY_ON = [
|
33
|
+
Ecoportal::API::Errors::TimeOut,
|
34
|
+
Ecoportal::API::Errors::StartTimeOut
|
35
|
+
].freeze
|
36
|
+
|
33
37
|
private
|
34
38
|
|
35
39
|
def batch_from(
|
@@ -48,7 +52,6 @@ module Eco
|
|
48
52
|
launch_batch(
|
49
53
|
data,
|
50
54
|
method: method,
|
51
|
-
per_page: params[:per_page] || batch_size(options),
|
52
55
|
people_api: people_api,
|
53
56
|
silent: silent,
|
54
57
|
options: options
|
@@ -59,54 +62,56 @@ module Eco
|
|
59
62
|
data,
|
60
63
|
method:,
|
61
64
|
status: nil,
|
62
|
-
job_mode: true,
|
65
|
+
job_mode: true,
|
63
66
|
options: self.options,
|
64
|
-
per_page: batch_size(options),
|
65
67
|
people_api: api&.people,
|
66
68
|
silent: false
|
67
69
|
)
|
68
|
-
iteration = 1
|
69
|
-
done = 0
|
70
|
-
iterations = (data.length.to_f / per_page).ceil
|
71
70
|
|
72
71
|
tap_status(status: status, enviro: enviro, queue: data, method: method) do |overall_status|
|
73
72
|
pending_for_server_error = data.to_a[0..]
|
74
73
|
|
75
|
-
|
74
|
+
batch_mode_on(*RETRY_ON, options: options, allow_job_mode: job_mode) do |job_mode, per_page|
|
75
|
+
iteration = 0
|
76
|
+
done = 0
|
77
|
+
iterations = (data.length.to_f / per_page).ceil
|
76
78
|
|
77
|
-
|
78
|
-
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, "
|
79
|
-
msg << "with #{slice.length} entries of #{data.length} -- #{done} done"
|
80
|
-
msg << (" " * 20)
|
81
|
-
log(:info) { msg } unless silent
|
79
|
+
start_time = Time.now
|
82
80
|
|
83
|
-
|
81
|
+
data.each_slice(per_page) do |slice|
|
82
|
+
iteration += 1
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
faltal("Request with no response") unless response
|
84
|
+
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, "
|
85
|
+
msg << "with #{slice.length} entries of #{data.length} -- #{done} done"
|
86
|
+
msg << (" " * 20)
|
87
|
+
log(:info) { msg } unless silent
|
90
88
|
|
91
|
-
|
89
|
+
start_slice = Time.now
|
92
90
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
91
|
+
offer_retry_on(*RETRY_ON, retries_left: TIMEOUT_RETRIES) do
|
92
|
+
people_api.batch(job_mode: job_mode) do |batch|
|
93
|
+
slice.each do |person|
|
94
|
+
batch.public_send(method, person) do |response|
|
95
|
+
faltal("Request with no response") unless response
|
99
96
|
|
100
|
-
|
97
|
+
next if server_error?(response)
|
101
98
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
99
|
+
pending_for_server_error.delete(person)
|
100
|
+
overall_status[person] = response
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end # end batch
|
104
|
+
end
|
105
|
+
|
106
|
+
done += slice.length
|
107
107
|
|
108
|
-
|
109
|
-
|
108
|
+
msg = " ... iteration #{iteration}/#{iterations} done "
|
109
|
+
msg << "in #{str_per_sec(start_slice, slice.length)} "
|
110
|
+
msg << "(average: #{str_per_sec(start_time, done)})"
|
111
|
+
msg << (" " * 20)
|
112
|
+
log(:info) { msg } unless silent
|
113
|
+
end # next slice
|
114
|
+
end
|
110
115
|
|
111
116
|
# temporary working around (due to back-end problems with batch/jobs)
|
112
117
|
unless pending_for_server_error.empty?
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -229,7 +229,7 @@ dependencies:
|
|
229
229
|
version: '0.10'
|
230
230
|
- - ">="
|
231
231
|
- !ruby/object:Gem::Version
|
232
|
-
version: 0.10.
|
232
|
+
version: 0.10.6
|
233
233
|
type: :runtime
|
234
234
|
prerelease: false
|
235
235
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -239,7 +239,7 @@ dependencies:
|
|
239
239
|
version: '0.10'
|
240
240
|
- - ">="
|
241
241
|
- !ruby/object:Gem::Version
|
242
|
-
version: 0.10.
|
242
|
+
version: 0.10.6
|
243
243
|
- !ruby/object:Gem::Dependency
|
244
244
|
name: ecoportal-api-graphql
|
245
245
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,7 +269,7 @@ dependencies:
|
|
269
269
|
version: '2.0'
|
270
270
|
- - ">="
|
271
271
|
- !ruby/object:Gem::Version
|
272
|
-
version: 2.0.
|
272
|
+
version: 2.0.11
|
273
273
|
type: :runtime
|
274
274
|
prerelease: false
|
275
275
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -279,7 +279,7 @@ dependencies:
|
|
279
279
|
version: '2.0'
|
280
280
|
- - ">="
|
281
281
|
- !ruby/object:Gem::Version
|
282
|
-
version: 2.0.
|
282
|
+
version: 2.0.11
|
283
283
|
- !ruby/object:Gem::Dependency
|
284
284
|
name: ed25519
|
285
285
|
requirement: !ruby/object:Gem::Requirement
|
@@ -658,10 +658,9 @@ files:
|
|
658
658
|
- lib/eco/api/session/batch/jobs_groups.rb
|
659
659
|
- lib/eco/api/session/batch/launcher.rb
|
660
660
|
- lib/eco/api/session/batch/launcher/benchmarking.rb
|
661
|
-
- lib/eco/api/session/batch/launcher/
|
661
|
+
- lib/eco/api/session/batch/launcher/mode_size.rb
|
662
662
|
- lib/eco/api/session/batch/launcher/options.rb
|
663
663
|
- lib/eco/api/session/batch/launcher/retry.rb
|
664
|
-
- lib/eco/api/session/batch/launcher/size.rb
|
665
664
|
- lib/eco/api/session/batch/launcher/status_handling.rb
|
666
665
|
- lib/eco/api/session/batch/launcher/valid_methods.rb
|
667
666
|
- lib/eco/api/session/batch/policies.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class Session
|
4
|
-
class Batch
|
5
|
-
module Launcher
|
6
|
-
module Mode
|
7
|
-
include Eco::API::Session::Batch::Launcher::Options
|
8
|
-
|
9
|
-
# @return [Symbol] the batch mode to run
|
10
|
-
def batch_mode(opts = options)
|
11
|
-
opts.dig(:workflow, :batch, :mode) || :batch
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Boolean] are we running in `:job` mode?
|
15
|
-
def job_mode?(opts = options)
|
16
|
-
batch_mode(opts) == :job
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class Session
|
4
|
-
class Batch
|
5
|
-
module Launcher
|
6
|
-
module Size
|
7
|
-
include Eco::API::Session::Batch::Launcher::Mode
|
8
|
-
|
9
|
-
DEFAULT_BATCH_SIZE = 50
|
10
|
-
DEFAULT_JOB_SIZE = 100
|
11
|
-
|
12
|
-
def batch_size(opts = options)
|
13
|
-
return job_mode_size if job_mode?(opts)
|
14
|
-
|
15
|
-
batch_mode_size
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def job_mode_size
|
21
|
-
options.dig(:workflow, :batch, :job, :size).then do |size|
|
22
|
-
next self.class::DEFAULT_JOB_SIZE unless size
|
23
|
-
|
24
|
-
size
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def batch_mode_size
|
29
|
-
options.dig(:workflow, :batch, :size).then do |size|
|
30
|
-
next self.class::DEFAULT_BATCH_SIZE unless size
|
31
|
-
|
32
|
-
[size, 100].min
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|