Sha256: e20dc9c078cee8a7593a6cd58816f989746b3ad5fa000b841143f3606a85ccc3

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

begin
  require "sidekiq/web"
rescue LoadError # rubocop:disable Lint/HandleExceptions
  # client-only usage
end

require_relative "web/helpers"

module SidekiqUniqueJobs
  # Utility module to help manage unique keys in redis.
  # Useful for deleting keys that for whatever reason wasn't deleted
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  module Web
    def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
      app.helpers do
        include Web::Helpers
      end

      app.get "/locks" do
        @filter         = params[:filter] || "*"
        @filter         = "*" if @filter == ""
        @count          = (params[:count] || 100).to_i
        @current_cursor = params[:cursor]
        @prev_cursor    = params[:prev_cursor]
        @pagination     = { pattern: @filter, cursor: @current_cursor, page_size: @count }
        @total_size, @next_cursor, @locks = digests.page(@pagination)

        erb(unique_template(:locks))
      end

      app.get "/locks/delete_all" do
        digests.del(pattern: "*", count: digests.count)
        redirect_to :locks
      end

      app.get "/locks/:digest" do
        @digest = params[:digest]
        @lock   = SidekiqUniqueJobs::Lock.new(@digest)

        erb(unique_template(:lock))
      end

      app.get "/locks/:digest/delete" do
        digests.del(digest: params[:digest])
        redirect_to :locks
      end

      app.get "/locks/:digest/jobs/:job_id/delete" do
        @digest = params[:digest]
        @lock   = SidekiqUniqueJobs::Lock.new(@digest)
        @lock.unlock(params[:job_id])

        redirect_to "locks/#{@lock.key}"
      end
    end
  end
end

if defined?(Sidekiq::Web)
  Sidekiq::Web.register SidekiqUniqueJobs::Web
  Sidekiq::Web.tabs["Locks"] = "locks"
  Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "locales")
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta4 lib/sidekiq_unique_jobs/web.rb
sidekiq-unique-jobs-7.0.0.beta3 lib/sidekiq_unique_jobs/web.rb
sidekiq-unique-jobs-7.0.0.beta2 lib/sidekiq_unique_jobs/web.rb