module Eco module API class Session class Batch module Launcher module ModeSize include Eco::API::Session::Batch::Launcher::Options DEFAULT_BATCH_SIZE = 50 DEFAULT_JOB_SIZE = 100 def batch_size(opts = options) return job_mode_size if job_mode?(opts) batch_mode_size end private # Swaps to batch endpoint on specific errors def batch_mode_on(*error_types, options: self.options, allow_job_mode: true) msg = "Expecting block. Non given" raise ArgumentError, msg unless block_given? in_job_mode = allow_job_mode && job_mode?(options) yield(in_job_mode, batch_size(options)) rescue *error_types raise unless in_job_mode yield(false, batch_mode_size) end # MODE # @return [Symbol] the batch mode to run def batch_mode(opts = options) opts.dig(:workflow, :batch, :mode) || :batch end # @return [Boolean] are we running in `:job` mode? def job_mode?(opts = options) batch_mode(opts) == :job end # SIZE def job_mode_size options.dig(:workflow, :batch, :job, :size).then do |size| next self.class::DEFAULT_JOB_SIZE unless size size end end def batch_mode_size options.dig(:workflow, :batch, :size).then do |size| next self.class::DEFAULT_BATCH_SIZE unless size [size, 100].min end end end end end end end end