-
Notifications
You must be signed in to change notification settings - Fork 112
/
web_extension.rb
95 lines (77 loc) · 2.66 KB
/
web_extension.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
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
94
95
module Sidekiq
module Failures
module WebExtension
def self.registered(app)
view_path = File.join(File.expand_path("..", __FILE__), "views")
app.helpers do
def safe_relative_time(time)
time = if time.is_a?(Numeric)
Time.at(time)
else
Time.parse(time)
end
relative_time(time)
end
end
app.get "/failures" do
@count = (params[:count] || 25).to_i
(@current_page, @total_size, @failures) = page(LIST_KEY, params[:page], @count, :reverse => true)
@failures = @failures.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
render(:erb, File.read(File.join(view_path, "failures.erb")))
end
app.get "/failures/:key" do
halt 404 unless params['key']
@failure = FailureSet.new.fetch(*parse_params(params['key'])).first
redirect "#{root_path}failures" if @failure.nil?
render(:erb, File.read(File.join(view_path, "failure.erb")))
end
app.post "/failures" do
halt 404 unless params['key']
params['key'].each do |key|
job = FailureSet.new.fetch(*parse_params(key)).first
next unless job
if params['retry']
job.retry_failure
elsif params['delete']
job.delete
end
end
redirect_with_query("#{root_path}failures")
end
app.post "/failures/:key" do
halt 404 unless params['key']
job = FailureSet.new.fetch(*parse_params(params['key'])).first
if job
if params['retry']
job.retry_failure
elsif params['delete']
job.delete
end
end
redirect_with_query("#{root_path}failures")
end
app.post "/failures/all/reset" do
Sidekiq::Failures.reset_failures
redirect "#{root_path}failures"
end
app.post "/failures/all/delete" do
FailureSet.new.clear
redirect "#{root_path}failures"
end
app.post "/failures/all/retry" do
FailureSet.new.retry_all_failures
redirect "#{root_path}failures"
end
app.get '/filter/failures' do
redirect "#{root_path}failures"
end
app.post '/filter/failures' do
@failures = Sidekiq::Failures::FailureSet.new.scan("*#{params[:substr]}*")
@current_page = 1
@count = @total_size = @failures.count
render(:erb, File.read(File.join(view_path, "failures.erb")))
end
end
end
end
end