Sha256: 3537608775762043d618e9277356962c7db69bd68aefd8c1fe17fc60a313fee9

Contents?: true

Size: 967 Bytes

Versions: 16

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module OnConflict
    # Strategy to reschedule job on conflict
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    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

16 entries across 16 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta25 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta24 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/on_conflict/reschedule.rb