Sha256: 88b3687055c133feab376c087b8ae45b522ee5e82d9aba665ba5d9dd49d56730

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 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)
              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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/session/batch/launcher/mode_size.rb
eco-helpers-3.0.20 lib/eco/api/session/batch/launcher/mode_size.rb