forked from livingsocial/resque-web
-
Notifications
You must be signed in to change notification settings - Fork 167
/
failures_controller.rb
62 lines (53 loc) · 1.63 KB
/
failures_controller.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
module ResqueWeb
class FailuresController < ResqueWeb::ApplicationController
# Display all jobs in the failure queue
#
# @param [Hash] params
# @option params [String] :class filters failures shown by class
# @option params [String] :queue filters failures shown by failure queue name
def index
end
# remove an individual job from the failure queue
def destroy
Resque::Failure.remove(params[:id])
redirect_to failures_path(redirect_params)
end
# destroy all jobs from the failure queue
def destroy_all
queue = params[:queue] || 'failed'
Resque::Failure.clear(queue)
redirect_to failures_path(redirect_params)
end
# retry an individual job from the failure queue
def retry
reque_single_job(params[:id])
redirect_to failures_path(redirect_params)
end
# retry all jobs from the failure queue
def retry_all
if params[:queue].present? && params[:queue]!="failed"
Resque::Failure.requeue_queue(params[:queue])
else
(Resque::Failure.count-1).downto(0).each { |id| reque_single_job(id) }
end
redirect_to failures_path(redirect_params)
end
private
#API agnostic for Resque 2 with duck typing on requeue_and_remove
def reque_single_job(id)
if Resque::Failure.respond_to?(:requeue_and_remove)
Resque::Failure.requeue_and_remove(id)
else
Resque::Failure.requeue(id)
Resque::Failure.remove(id)
end
end
def redirect_params
{}.tap do |p|
if params[:queue].present?
p[:queue] = params[:queue]
end
end
end
end
end