eco-helpers 2.0.42 → 2.0.43
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/CHANGELOG.md +11 -0
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +1 -1
- data/lib/eco/api/session/batch/job.rb +2 -1
- data/lib/eco/api/session/batch.rb +40 -3
- data/lib/eco/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc85b6b42cc78adcdf2cba976331b5ae0202464ade71bb9f6b72793c28c4e8f0
|
4
|
+
data.tar.gz: 3ab9745bb62f78df1bdd6ec9657607d4135cce910c643fb9adedbb42b315e022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 339e768dd7de68dd4f87743003bb1d177220a7ac47808b19cbcf837f16a75e1d7c3f65ce427e67542e0fe318be8b2b2531f5bd0e99743bd049c03c1711965aa0
|
7
|
+
data.tar.gz: 26b8d2e9a17e8ae7ad447ea3c28a9ce02d1726c0d78839175fc1a432c5c8aff63dde66a2bcec4bca94c745cdd794e5a0caf3a5e25008e159a3c29ead2fd707c9
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.0.43] - 2021-11-25
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::Session::Batch::Job` added better **logging**
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
- `Eco::API::Session::Batch` added **resilience** and **recovery** to connection errors
|
11
|
+
- `Eco::API::Policies::DefaultPolicies::UserAccess` changed logging from `warn` to `info`.
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
4
15
|
## [2.0.42] - 2021-10-30
|
5
16
|
|
6
17
|
### Added
|
@@ -22,7 +22,7 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
22
22
|
def warn_account_removal!
|
23
23
|
if account_removed_count > 0
|
24
24
|
msg = "(DefaultPolicy on job '#{job.name}') Removed account to #{account_removed_count} people"
|
25
|
-
session.logger.
|
25
|
+
session.logger.info(msg)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -176,6 +176,7 @@ module Eco
|
|
176
176
|
if pqueue.length > 0
|
177
177
|
req_backup = as_update(pqueue, add_feedback: false)
|
178
178
|
backup_update(req_backup)
|
179
|
+
logger.debug("Job ('#{name}':#{type}): going to launch batch against #{pqueue.count} entries")
|
179
180
|
session.batch.launch(pqueue, method: type).tap do |job_status|
|
180
181
|
@status = job_status
|
181
182
|
status.root = self
|
@@ -334,7 +335,7 @@ module Eco
|
|
334
335
|
handlers.each do |handler|
|
335
336
|
if entries = err_types[handler.name]
|
336
337
|
handler_job = subjobs_add("#{self.name} => #{handler.name}", usecase: handler)
|
337
|
-
logger.debug("Running error handler #{handler.name}")
|
338
|
+
logger.debug("Running error handler #{handler.name} (against #{entries.count} entries)")
|
338
339
|
handler.launch(people: people(entries), session: session, options: options, job: handler_job)
|
339
340
|
logger.debug("Launching job of error handler: #{handler_job.name}")
|
340
341
|
handler_job.launch(simulate: simulate)
|
@@ -92,6 +92,7 @@ module Eco
|
|
92
92
|
return people_api.get_all(params: params, silent: silent)
|
93
93
|
end
|
94
94
|
|
95
|
+
|
95
96
|
def batch_from(data, method:, params: {}, silent: false)
|
96
97
|
fatal "Invalid batch method: #{method}." if !self.class.valid_method?(method)
|
97
98
|
return nil if !data || !data.is_a?(Enumerable)
|
@@ -101,12 +102,23 @@ module Eco
|
|
101
102
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
102
103
|
per_page = params[:per_page] || DEFAULT_BATCH_BLOCK
|
103
104
|
|
105
|
+
launch_batch(data,
|
106
|
+
method: method,
|
107
|
+
per_page: per_page,
|
108
|
+
people_api: people_api,
|
109
|
+
silent: silent
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
def launch_batch(data, method:, status: nil, job_mode: true, per_page: DEFAULT_BATCH_BLOCK, people_api: api&.people, silent: false)
|
104
114
|
iteration = 1; done = 0
|
105
115
|
iterations = (data.length.to_f / per_page).ceil
|
106
116
|
|
107
|
-
Eco::API::Session::Batch::Status.new(enviro, queue: data, method: method)
|
117
|
+
status ||= Eco::API::Session::Batch::Status.new(enviro, queue: data, method: method)
|
118
|
+
status.tap do |status|
|
108
119
|
start_time = Time.now
|
109
120
|
start_slice = Time.now; slice = []
|
121
|
+
pending_for_server_error = data.to_a[0..-1]
|
110
122
|
data.each_slice(per_page) do |slice|
|
111
123
|
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations},"
|
112
124
|
msg += " with #{slice.length} entries of #{data.length} -- #{done} done"
|
@@ -115,11 +127,14 @@ module Eco
|
|
115
127
|
|
116
128
|
start_slice = Time.now
|
117
129
|
offer_retry_on(Ecoportal::API::Errors::TimeOut) do
|
118
|
-
people_api.batch do |batch|
|
130
|
+
people_api.batch(job_mode: false) do |batch|
|
119
131
|
slice.each do |person|
|
120
132
|
batch.public_send(method, person) do |response|
|
121
133
|
faltal("Request with no response") unless !!response
|
122
|
-
|
134
|
+
unless server_error?(response)
|
135
|
+
pending_for_server_error.delete(person)
|
136
|
+
status[person] = response
|
137
|
+
end
|
123
138
|
end
|
124
139
|
end
|
125
140
|
end # end batch
|
@@ -128,9 +143,31 @@ module Eco
|
|
128
143
|
iteration += 1
|
129
144
|
done += slice.length
|
130
145
|
end # next slice
|
146
|
+
|
147
|
+
# temporary working around (due to back-end problems with batch/jobs)
|
148
|
+
unless pending_for_server_error.empty?
|
149
|
+
msg = "Going to re-try #{pending_for_server_error.count} due to server errors"
|
150
|
+
logger.info(msg) unless silent
|
151
|
+
launch_batch(pending_for_server_error,
|
152
|
+
status: status,
|
153
|
+
method: method,
|
154
|
+
job_mode: false,
|
155
|
+
per_page: per_page,
|
156
|
+
people_api: people_api,
|
157
|
+
silent: silent
|
158
|
+
)
|
159
|
+
end
|
131
160
|
end
|
132
161
|
end
|
133
162
|
|
163
|
+
def server_error?(response)
|
164
|
+
res_status = response.status
|
165
|
+
server_error = !res_status || res_status.server_error?
|
166
|
+
other_error = !server_error && (!res_status.code || res_status.code < 100)
|
167
|
+
no_body = !server_error && !other_error && !response.body
|
168
|
+
server_error || other_error || no_body
|
169
|
+
end
|
170
|
+
|
134
171
|
def offer_retry_on(error_type, retries_left = 3, &block)
|
135
172
|
begin
|
136
173
|
block.call
|
data/lib/eco/version.rb
CHANGED