Sha256: 2c74528c666bbd61cc381d93d0e119227f125a6389bf7de87e639223d171c68f

Contents?: true

Size: 967 Bytes

Versions: 4

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module OnConflict
    # Strategy to reschedule job on conflict
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    class Reschedule < OnConflict::Strategy
      include SidekiqUniqueJobs::SidekiqWorkerMethods
      include SidekiqUniqueJobs::Logging
      include SidekiqUniqueJobs::JSON

      # @param [Hash] item sidekiq job hash
      def initialize(item, redis_pool = nil)
        super(item, redis_pool)
        @worker_class = item[CLASS]
      end

      # Create a new job from the current one.
      #   This will mess up sidekiq stats because a new job is created
      def call
        if sidekiq_worker_class?
          log_info("Rescheduling #{item[LOCK_DIGEST]}")
          worker_class&.perform_in(5, *item[ARGS])
        else
          log_warn("Skip rescheduling of #{item[LOCK_DIGEST]} because #{worker_class} is not a Sidekiq::Worker")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta29 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta28 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta27 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta26 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb