Module: SidekiqUniqueJobs::Web

Defined in:
lib/sidekiq_unique_jobs/web.rb,
lib/sidekiq_unique_jobs/web/helpers.rb

Overview

Utility module to help manage unique keys in redis. Useful for deleting keys that for whatever reason wasn’t deleted

Author:

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sidekiq_unique_jobs/web.rb', line 10

def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  app.helpers do
    include Web::Helpers
  end

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

    erb(unique_template(:changelogs))
  end

  app.get "/changelogs/delete_all" do
    changelog.clear
    redirect_to :changelogs
  end

  app.get "/locks" do
    @filter         = params[:filter] || "*"
    @filter         = "*" if @filter == ""
    @count          = (params[:count] || 100).to_i
    @current_cursor = params[:cursor].to_i
    @prev_cursor    = params[:prev_cursor].to_i

    @total_size, @next_cursor, @locks = digests.page(
      cursor: @current_cursor,
      pattern: @filter,
      page_size: @count,
    )

    erb(unique_template(:locks))
  end

  app.get "/expiring_locks" do
    @filter         = params[:filter] || "*"
    @filter         = "*" if @filter == ""
    @count          = (params[:count] || 100).to_i
    @current_cursor = params[:cursor].to_i
    @prev_cursor    = params[:prev_cursor].to_i

    @total_size, @next_cursor, @locks = expiring_digests.page(
      cursor: @current_cursor,
      pattern: @filter,
      page_size: @count,
    )

    erb(unique_template(:locks))
  end

  app.get "/locks/delete_all" do
    digests.delete_by_pattern("*", count: digests.count)
    expiring_digests.delete_by_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.delete_by_digest(params[:digest])
    expiring_digests.delete_by_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