resque-job-killer 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b76b0f851417e73b0fb83f2f5a7a8b4d2ee7642c5c17cafa365aef3f3fc5bbac
|
|
4
|
+
data.tar.gz: 73ebfe56a1999e692227ac17d3114ea94c2110465b1d3d7d09605263e115fe8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 282af571a1208a0eff79254190c2d50cbb9d20ef23a181817f052b5b3ddca6227959bd99ecc845dc32da4d7eb62fc1d1143bebf8561e76e5faeae18906fb720f
|
|
7
|
+
data.tar.gz: b2862d071a2414f4d17045439179f19d1e6a44d9f7e0e1b7a449192345f448cce2a18cc85a8cb372cc5dc4742836f344f2cd600493bd1f07f803d3019b0a061a
|
|
@@ -1,46 +1,50 @@
|
|
|
1
1
|
module Resque
|
|
2
2
|
module Plugins
|
|
3
3
|
module JobKiller
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
def self.kill_job(job_id)
|
|
5
|
+
worker, queue = detect_worker_and_queue(job_id)
|
|
6
|
+
return unless worker
|
|
7
|
+
|
|
8
|
+
pause_worker(worker)
|
|
9
|
+
kill_child(worker)
|
|
10
|
+
dequeue_job(job_id, queue)
|
|
11
|
+
unpause_worker(worker)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
Resque.redis.lpush(HISTORY_SET_NAME, {:class => "#{self}",
|
|
14
|
-
:time => Time.now.strftime("%Y-%m-%d %H:%M:%S %z"),
|
|
15
|
-
:args => args,
|
|
16
|
-
:error => exception.message
|
|
17
|
-
}.to_json)
|
|
14
|
+
private
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
def detect_worker_and_queue(job_id)
|
|
17
|
+
worker = Resque.workers.detect do |worker|
|
|
18
|
+
worker.job.dig('payload', 'args')&.first&.dig('job_id') == job_id
|
|
19
|
+
end
|
|
22
20
|
|
|
21
|
+
[worker, worker.job['queue']]
|
|
23
22
|
end
|
|
24
23
|
|
|
24
|
+
def kill_child(worker)
|
|
25
|
+
Process.kill(:USR1, worker.pid)
|
|
26
|
+
end
|
|
25
27
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
+
def pause_worker(worker)
|
|
29
|
+
Process.kill(:USR2, worker.pid)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
|
-
def
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
:args => args,
|
|
34
|
-
:time => Time.now.strftime("%Y-%m-%d %H:%M:%S %z"),
|
|
35
|
-
:execution =>elapsed_seconds
|
|
36
|
-
}.to_json)
|
|
32
|
+
def unpause_worker(worker)
|
|
33
|
+
Process.kill(:CONT, worker.pid)
|
|
34
|
+
end
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
end
|
|
36
|
+
def dequeue_job(job_id, queue_name)
|
|
37
|
+
job = detect_job(job_id, queue_name)
|
|
41
38
|
|
|
39
|
+
Resque.redis.lrem("queue:#{queue_name}", -1, job)
|
|
42
40
|
end
|
|
43
41
|
|
|
42
|
+
def detect_job(job_id, queue_name)
|
|
43
|
+
Resque.redis.lrange("queue:#{queue_name}", 0, -1)
|
|
44
|
+
.detect do |job|
|
|
45
|
+
Resque.decode(job).dig('args', 'job_id') == job_id
|
|
46
|
+
end
|
|
47
|
+
end
|
|
44
48
|
end
|
|
45
49
|
end
|
|
46
50
|
end
|
|
@@ -1,62 +1,49 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<%
|
|
19
|
-
|
|
20
|
-
<div id="main">
|
|
21
|
-
<%= erb File.read(ResqueHistory::Server.erb_path('navigation.erb')), {},
|
|
22
|
-
:start => params[:start].to_i, :size => size %>
|
|
23
|
-
|
|
24
|
-
<table>
|
|
1
|
+
<%
|
|
2
|
+
workers = resque.working
|
|
3
|
+
jobs = workers.collect {|w| w.job }
|
|
4
|
+
worker_jobs = workers.zip(jobs)
|
|
5
|
+
worker_jobs = worker_jobs.reject { |w, j| w.idle? }
|
|
6
|
+
%>
|
|
7
|
+
|
|
8
|
+
<h1 class='wi'><%= worker_jobs.size %> of <%= resque.workers.size %> Workers Working</h1>
|
|
9
|
+
<p class='intro'>The list below contains all workers which are currently running a job.</p>
|
|
10
|
+
<table class='workers'>
|
|
11
|
+
<tr>
|
|
12
|
+
<th> </th>
|
|
13
|
+
<th>Where</th>
|
|
14
|
+
<th>Queue</th>
|
|
15
|
+
<th>Processing</th>
|
|
16
|
+
<th> </th>
|
|
17
|
+
</tr>
|
|
18
|
+
<% if worker_jobs.empty? %>
|
|
25
19
|
<tr>
|
|
26
|
-
<
|
|
27
|
-
<th>Arguments</th>
|
|
28
|
-
<th>Time</th>
|
|
29
|
-
<th>Execution</th>
|
|
20
|
+
<td colspan="4" class='no-data'>Nothing is happening right now...</td>
|
|
30
21
|
</tr>
|
|
31
|
-
|
|
32
|
-
<% j = JSON.parse(history, :symbolize_names => true, :symbolize_keys => true) %>
|
|
33
|
-
<tr class='<%= j[:error].nil? ? "" : "failure" %>' >
|
|
34
|
-
<td class='queue'><%= j[:class] %></td>
|
|
35
|
-
<td class='argument'><pre><%= j[:args] ? show_args(j[:args]) : '' %></pre></td>
|
|
36
|
-
<td class='time'><%= j[:time] %></td>
|
|
37
|
-
<td class='execution'><%= format_execution(j[:execution]) %></td>
|
|
38
|
-
</tr>
|
|
39
|
-
<% end %>
|
|
40
|
-
</table>
|
|
22
|
+
<% end %>
|
|
41
23
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
</
|
|
24
|
+
<% worker_jobs.sort_by {|w, j| j['run_at'] ? j['run_at'].to_s() : '' }.each do |worker, job| %>
|
|
25
|
+
<tr>
|
|
26
|
+
<td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
|
|
27
|
+
<% host, pid, queues = worker.to_s.split(':') %>
|
|
28
|
+
<td class='where'><a href="<%=u "/workers/#{worker}" %>"><%= host %>:<%= pid %></a></td>
|
|
29
|
+
<td class='queues queue'>
|
|
30
|
+
<a class="queue-tag" href="<%=u "/queues/#{job['queue']}" %>"><%= job['queue'] %></a>
|
|
31
|
+
</td>
|
|
32
|
+
<td class='process'>
|
|
33
|
+
<% if job['queue'] %>
|
|
34
|
+
<%= partial :processing, :worker => worker, :job => job %>
|
|
35
|
+
<% else %>
|
|
36
|
+
<span class='waiting'>Waiting for a job...</span>
|
|
37
|
+
<% end %>
|
|
38
|
+
</td>
|
|
39
|
+
<td>
|
|
40
|
+
<% job_id = job.dig('payload','args')&.first&.dig('job_id') %>
|
|
41
|
+
<% if job_id %>
|
|
42
|
+
<form method="DELETE" action="<%= u "job_killer/kill/#{job_id}" %>">
|
|
43
|
+
<input type="submit" name="" value="Kill job" onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
|
|
44
|
+
</form>
|
|
45
|
+
<% end %>
|
|
46
|
+
</td>
|
|
47
|
+
</tr>
|
|
48
|
+
<% end %>
|
|
49
|
+
</table>
|
|
@@ -23,10 +23,18 @@ module ResqueJobKiller
|
|
|
23
23
|
erb File.read(ResqueJobKiller::Server.erb_path('job_killer.erb'))
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
delete '/job_killer/kill:job_id' do
|
|
27
|
+
raise 'No job_id was provided' unless params[:job_id]
|
|
28
|
+
|
|
29
|
+
Resque::Plugins::JobKiller.kill_job(params[:job_id])
|
|
30
|
+
|
|
31
|
+
redirect 'resque/job_killer'
|
|
32
|
+
end
|
|
33
|
+
|
|
26
34
|
end
|
|
27
35
|
end
|
|
28
36
|
|
|
29
|
-
Resque::Server.tabs << '
|
|
37
|
+
Resque::Server.tabs << 'Job_Killer'
|
|
30
38
|
end
|
|
31
39
|
end
|
|
32
40
|
|