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
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/sidekiq/results/web_extension.rb', line 4
def self.registered(app)
view_path = File.join(File.expand_path("..", __FILE__), "views")
locale_path = File.expand_path(File.dirname(__FILE__) + '/locales')
Sidekiq::Web.settings.locales << locale_path
app.helpers do
def status_label(status)
labels = {
'busy' => '▶',
'processed' => '✅',
'failed' => '❌',
}
labels[status]
end
end
app.get '/results' do
@count = (params[:count] || 25).to_i
(@current_page, @total_size, @results) = page(LIST_KEY, params[:page], @count, reverse: true)
@results = @results.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
render(:erb, File.read(File.join(view_path, 'index.html.erb')))
end
app.post '/results' do
redirect("#{root_path}results") unless params['key']
params['key'].each do |key|
job = @result = ResultSet.new.fetch(*parse_params(params['key'])).first
retry_or_delete_or_kill job, params if job
end
redirect_with_query("#{root_path}morgue")
end
app.get '/results/:key' do
halt 404 unless params['key']
@result = ResultSet.new.fetch(*parse_params(params['key'])).first
redirect("#{root_path}results") unless @result
render(:erb, File.read(File.join(view_path, 'show.html.erb')))
end
app.post "/results/:key" do
halt 404 unless params['key']
job = ResultSet.new.fetch(*parse_params(params['key'])).first
retry_or_delete_or_kill job, params if job
redirect_with_query("#{root_path}results")
end
app.post "/results/all/delete" do
ResultSet.new.clear
redirect "#{root_path}results"
end
app.get '/filter/results' do
redirect "#{root_path}results"
end
app.post '/filter/results' do
@results = Sidekiq::Failures::FailureSet.new.scan("*#{params[:substr]}*")
@current_page = 1
@count = @total_size = @results.size
render(:erb, File.read(File.join(view_path, 'index.html.erb')))
end
end
|