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