Sha256: f746d8b7bc1dd14c026f32c3dc5d4b3c06a650c661657cc04b3cd90efbf5369b

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 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

    #
    # Start the sidekiq unique jobs server process
    #
    #
    # @return [void]
    #
    def self.start
      SidekiqUniqueJobs::UpdateVersion.call
      SidekiqUniqueJobs::Orphans::Manager.start
      SidekiqUniqueJobs::Orphans::ReaperResurrector.start
    end

    #
    # Stop the sidekiq unique jobs server process
    #
    #
    # @return [void]
    #
    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

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/server.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/server.rb