lib/eco/api/session/batch.rb in eco-helpers-3.0.7 vs lib/eco/api/session/batch.rb in eco-helpers-3.0.8
- old
+ new
@@ -10,10 +10,20 @@
def valid_method?(value)
VALID_METHODS.include?(value)
end
end
+ # @return [Symbol] the batch mode to run
+ def batch_mode(opts = self.options)
+ opts.dig(:workflow, :batch, :mode) || :batch
+ end
+
+ # @return [Boolean] are we running in `:job` mode?
+ def job_mode?(opts = self.options)
+ batch_mode(opts) == :job
+ end
+
# Gets the _people_ of the organization according `params`.
# If `people` is not `nil`, scopes to only the people specified.
# @note
# - If `people` is given keys `page:` and `q` of `params:`.
# @param people [Nil, People, Enumerable<Person>, Enumerable<Hash>] target _People_ to launch the batch against.
@@ -111,18 +121,24 @@
people_api: people_api,
silent: silent
)
end
+ # Default way to retrieve options (unless provided)
+ def options
+ ASSETS.cli.options
+ end
+
def launch_batch( # rubocop:disable Metrics/AbcSize
data,
method:,
status: nil,
job_mode: true, # rubocop:disable Lint/UnusedMethodArgument
per_page: DEFAULT_BATCH_BLOCK,
people_api: api&.people,
- silent: false
+ silent: false,
+ options: self.options
)
iteration = 1
done = 0
iterations = (data.length.to_f / per_page).ceil
@@ -143,10 +159,10 @@
msg << " (last: #{str_stats(start_slice, slice.length)}; total: #{str_stats(start_time, done)})"
log(:info) { msg } unless silent
start_slice = Time.now
offer_retry_on(Ecoportal::API::Errors::TimeOut) do
- people_api.batch(job_mode: false) do |batch|
+ people_api.batch(job_mode: job_mode?(options)) do |batch|
slice.each do |person|
batch.public_send(method, person) do |response|
faltal("Request with no response") unless response
next if server_error?(response)