Sha256: f8af11e9d6adf0834ed4066a0283a2e622ac07f74099abb84c9fa5784e91f509

Contents?: true

Size: 897 Bytes

Versions: 8

Compression:

Stored size: 897 Bytes

Contents

module SidekiqUniqueJobs
  class TimeoutCalculator
    def self.for_item(item)
      new(item)
    end

    def initialize(item)
      @item = item
    end

    def seconds
      time_until_scheduled + unique_expiration
    end

    def time_until_scheduled
      scheduled = item[AT_KEY]
      return 0 unless scheduled
      (Time.at(scheduled) - Time.now.utc).to_i
    end

    def unique_expiration
      @unique_expiration ||=
        (
          worker_class_unique_expiration ||
          SidekiqUniqueJobs.config.default_expiration
        ).to_i
    end

    def worker_class_unique_expiration
      return unless worker_class.respond_to?(:get_sidekiq_options)
      worker_class.get_sidekiq_options[UNIQUE_TIMEOUT_KEY]
    end

    def worker_class
      @worker_class ||= SidekiqUniqueJobs.worker_class_constantize(item[CLASS_KEY])
    end

    private

    attr_reader :item
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.15 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.13 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.12 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.11 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.10 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.9 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.8 lib/sidekiq_unique_jobs/timeout_calculator.rb
sidekiq-unique-jobs-4.0.7 lib/sidekiq_unique_jobs/timeout_calculator.rb