module JobIteration

typed: true

Constants

INTEGRATIONS
IntegrationLoadError
VERSION

Attributes

enumerator_builder[RW]

Set if you want to use your own enumerator builder instead of default EnumeratorBuilder. @example

class MyOwnBuilder < JobIteration::EnumeratorBuilder
  # ...
end

JobIteration.enumerator_builder = MyOwnBuilder
interruption_adapter[RW]

Used internally for hooking into job processing frameworks like Sidekiq and Resque.

max_job_runtime[RW]

Use this to always interrupt the job after it's been running for more than N seconds. @example

JobIteration.max_job_runtime = 5.minutes

This setting will make it to always interrupt a job after it's been iterating for 5 minutes. Defaults to nil which means that jobs will not be interrupted except on termination signal.

Public Instance Methods

load_integration(integration) click to toggle source
# File lib/job-iteration.rb, line 54
def load_integration(integration)
  unless INTEGRATIONS.include?(integration)
    raise IntegrationLoadError,
      "#{integration} integration is not supported. Available integrations: #{INTEGRATIONS.join(", ")}"
  end

  require_relative "./job-iteration/integrations/#{integration}"
end
load_integrations() click to toggle source
# File lib/job-iteration.rb, line 38
def load_integrations
  loaded = nil
  INTEGRATIONS.each do |integration|
    begin
      load_integration(integration)
      if loaded
        raise IntegrationLoadError,
          "#{loaded} integration has already been loaded, but #{integration} is also available. " \
          "Iteration will only work with one integration."
      end
      loaded = integration
    rescue LoadError
    end
  end
end