Sha256: 95dd38585ccb2003da9cbfe3f2407f71019288d2e4bc8652f73dcaaf4c07774b

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # The unique sidekiq middleware for the server processor
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  class Server
    DEATH_HANDLER ||= (lambda do |job, _ex|
      return unless (digest = job["lock_digest"])

      SidekiqUniqueJobs::Digests.new.delete_by_digest(digest)
    end).freeze
    #
    # Configure the server middleware
    #
    #
    # @return [Sidekiq] the sidekiq configuration
    #
    def self.configure(config)
      config.on(:startup)  { start }
      config.on(:shutdown) { stop }

      return unless config.respond_to?(:death_handlers)

      config.death_handlers << death_handler
    end

    def self.start
      SidekiqUniqueJobs::UpdateVersion.call
      SidekiqUniqueJobs::UpgradeLocks.call
      SidekiqUniqueJobs::Orphans::Manager.start
      SidekiqUniqueJobs::Orphans::ReaperResurrector.start
    end

    def self.stop
      SidekiqUniqueJobs::Orphans::Manager.stop
    end

    #
    # A death handler for dead jobs
    #
    #
    # @return [lambda]
    #
    def self.death_handler
      DEATH_HANDLER
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.1.6 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-7.1.5 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-7.1.3 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-7.1.2 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-7.1.1 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-7.1.0 lib/sidekiq_unique_jobs/server.rb