-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
web.rb
60 lines (50 loc) · 1.81 KB
/
web.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true
begin
require "delegate"
require "rack"
require "sidekiq/web"
rescue LoadError # rubocop:disable Lint/SuppressedException
# 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
app.helpers do
include Web::Helpers
end
app.get "/unique_digests" do
@filter = params[:filter] || "*"
@filter = "*" if @filter == ""
@count = (params[:count] || 100).to_i
@current_cursor = params[:cursor]
@prev_cursor = params[:prev_cursor]
@total_size, @next_cursor, @unique_digests =
SidekiqUniqueJobs::Digests.page(pattern: @filter, cursor: @current_cursor, page_size: @count)
erb(unique_template(:unique_digests))
end
app.get "/unique_digests/delete_all" do
SidekiqUniqueJobs::Digests.delete_by_pattern("*", count: SidekiqUniqueJobs::Digests.count)
redirect_to :unique_digests
end
app.get "/unique_digests/:digest" do
@digest = params[:digest]
@unique_keys = SidekiqUniqueJobs::Util.keys("#{@digest}*", 1000)
erb(unique_template(:unique_digest))
end
app.get "/unique_digests/:digest/delete" do
SidekiqUniqueJobs::Digests.delete_by_digest(params[:digest])
redirect_to :unique_digests
end
end
end
end
if defined?(Sidekiq::Web)
Sidekiq::Web.register SidekiqUniqueJobs::Web
Sidekiq::Web.tabs["Unique Digests"] = "unique_digests"
# Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), 'locales')
end