Sha256: e81eff2c35efae4b8adc526c77399198dea3a4c24d30077eaab7bed8530f2862

Contents?: true

Size: 1.05 KB

Versions: 47

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Spotlight
  # Job status tracking
  module LimitConcurrency
    extend ActiveSupport::Concern

    VALIDITY_TOKEN_PARAMETER = 'validity_token'

    included do
      # The validity checker is a seam for implementations to expire unnecessary
      # indexing tasks if it becomes redundant while waiting in the job queue.
      class_attribute :validity_checker, default: Spotlight::ValidityChecker.new

      before_enqueue do |job|
        token = job.arguments.last[VALIDITY_TOKEN_PARAMETER] if job.arguments.last.is_a?(Hash)
        token ||= validity_checker.mint(job)

        job.arguments << {} unless job.arguments.last.is_a? Hash
        job.arguments.last[VALIDITY_TOKEN_PARAMETER] = token
      end

      before_perform do |job|
        next unless job.arguments.last.is_a?(Hash)

        token = job.arguments.last.delete(VALIDITY_TOKEN_PARAMETER)
        throw(:abort) unless token.nil? || validity_checker.check(job, validity_token: token)

        job.arguments.pop if job.arguments.last.empty?
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.3 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.6.0.beta6 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.6.0.beta5 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.6.0.beta4 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.6.0.beta3 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.6.0.beta1 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.5.0.2 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.5.0.1 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.5.0 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.4.1 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.4 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.3 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.2.2 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.2.1 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.2 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.1 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.4.0 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.3.0 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.2.0 app/jobs/concerns/spotlight/limit_concurrency.rb
blacklight-spotlight-3.1.0 app/jobs/concerns/spotlight/limit_concurrency.rb