Sha256: fa8f361debd23b9e12d1ac183d339c13347e09634f0784b7b9422c60b560fcdd

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

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, &block)
              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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eco-helpers-3.0.19 lib/eco/api/session/batch/launcher/mode_size.rb
eco-helpers-3.0.18 lib/eco/api/session/batch/launcher/mode_size.rb