tr_resque 1.20.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +354 -0
- data/LICENSE +20 -0
- data/README.markdown +908 -0
- data/Rakefile +70 -0
- data/bin/resque +81 -0
- data/bin/resque-web +27 -0
- data/lib/resque.rb +369 -0
- data/lib/resque/errors.rb +10 -0
- data/lib/resque/failure.rb +96 -0
- data/lib/resque/failure/airbrake.rb +17 -0
- data/lib/resque/failure/base.rb +64 -0
- data/lib/resque/failure/hoptoad.rb +33 -0
- data/lib/resque/failure/multiple.rb +54 -0
- data/lib/resque/failure/redis.rb +51 -0
- data/lib/resque/failure/thoughtbot.rb +33 -0
- data/lib/resque/helpers.rb +94 -0
- data/lib/resque/job.rb +227 -0
- data/lib/resque/plugin.rb +66 -0
- data/lib/resque/server.rb +248 -0
- data/lib/resque/server/public/favicon.ico +0 -0
- data/lib/resque/server/public/idle.png +0 -0
- data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
- data/lib/resque/server/public/jquery.relatize_date.js +95 -0
- data/lib/resque/server/public/poll.png +0 -0
- data/lib/resque/server/public/ranger.js +73 -0
- data/lib/resque/server/public/reset.css +44 -0
- data/lib/resque/server/public/style.css +86 -0
- data/lib/resque/server/public/working.png +0 -0
- data/lib/resque/server/test_helper.rb +19 -0
- data/lib/resque/server/views/error.erb +1 -0
- data/lib/resque/server/views/failed.erb +67 -0
- data/lib/resque/server/views/key_sets.erb +19 -0
- data/lib/resque/server/views/key_string.erb +11 -0
- data/lib/resque/server/views/layout.erb +44 -0
- data/lib/resque/server/views/next_more.erb +10 -0
- data/lib/resque/server/views/overview.erb +4 -0
- data/lib/resque/server/views/queues.erb +49 -0
- data/lib/resque/server/views/stats.erb +62 -0
- data/lib/resque/server/views/workers.erb +109 -0
- data/lib/resque/server/views/working.erb +72 -0
- data/lib/resque/stat.rb +53 -0
- data/lib/resque/tasks.rb +61 -0
- data/lib/resque/version.rb +3 -0
- data/lib/resque/worker.rb +546 -0
- data/lib/tasks/redis.rake +161 -0
- data/lib/tasks/resque.rake +2 -0
- data/test/airbrake_test.rb +27 -0
- data/test/hoptoad_test.rb +26 -0
- data/test/job_hooks_test.rb +423 -0
- data/test/job_plugins_test.rb +230 -0
- data/test/plugin_test.rb +116 -0
- data/test/redis-test-cluster.conf +115 -0
- data/test/redis-test.conf +115 -0
- data/test/resque-web_test.rb +59 -0
- data/test/resque_test.rb +278 -0
- data/test/test_helper.rb +160 -0
- data/test/worker_test.rb +434 -0
- metadata +186 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Resque.</title>
|
6
|
+
<link href="<%=u 'reset.css' %>" media="screen" rel="stylesheet" type="text/css">
|
7
|
+
<link href="<%=u 'style.css' %>" media="screen" rel="stylesheet" type="text/css">
|
8
|
+
<script src="<%=u 'jquery-1.3.2.min.js' %>" type="text/javascript"></script>
|
9
|
+
<script src="<%=u 'jquery.relatize_date.js' %>" type="text/javascript"></script>
|
10
|
+
<script src="<%=u 'ranger.js' %>" type="text/javascript"></script>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<div class="header">
|
14
|
+
<ul class='nav'>
|
15
|
+
<% tabs.each do |tab_name| %>
|
16
|
+
<%= tab tab_name %>
|
17
|
+
<% end %>
|
18
|
+
</ul>
|
19
|
+
<% if Resque.redis.namespace != :resque %>
|
20
|
+
<abbr class="namespace" title="Resque's Redis Namespace">
|
21
|
+
<%= Resque.redis.namespace %>
|
22
|
+
</abbr>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<% if @subtabs %>
|
27
|
+
<ul class='subnav'>
|
28
|
+
<% for subtab in @subtabs %>
|
29
|
+
<li <%= class_if_current "#{current_section}/#{subtab}" %>><a href="<%= current_section %>/<%= subtab %>"><span><%= subtab %></span></a></li>
|
30
|
+
<% end %>
|
31
|
+
</ul>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<div id="main">
|
35
|
+
<%= yield %>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<div id="footer">
|
39
|
+
<p>Powered by <a href="http://github.com/defunkt/resque">Resque</a> v<%=Resque::Version%></p>
|
40
|
+
<p>Connected to Redis namespace <%= Resque.redis.namespace %> on <%=Resque.redis_id%></p>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
</body>
|
44
|
+
</html>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%if start - 20 >= 0 || start + 20 <= size%>
|
2
|
+
<p class='pagination'>
|
3
|
+
<% if start - 20 >= 0 %>
|
4
|
+
<a href="<%= current_page %>?start=<%= start - 20 %>" class='less'>« less</a>
|
5
|
+
<% end %>
|
6
|
+
<% if start + 20 <= size %>
|
7
|
+
<a href="<%= current_page %>?start=<%= start + 20 %>" class='more'>more »</a>
|
8
|
+
<% end %>
|
9
|
+
</p>
|
10
|
+
<%end%>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<% @subtabs = resque.queues unless partial? || params[:id].nil? %>
|
2
|
+
|
3
|
+
<% if queue = params[:id] %>
|
4
|
+
|
5
|
+
<h1>Pending jobs on <span class='hl'><%= queue %></span></h1>
|
6
|
+
<form method="POST" action="<%=u "/queues/#{queue}/remove" %>" class='remove-queue'>
|
7
|
+
<input type='submit' name='' value='Remove Queue' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
|
8
|
+
</form>
|
9
|
+
<p class='sub'>Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = resque.size(queue)%></b> jobs</p>
|
10
|
+
<table class='jobs'>
|
11
|
+
<tr>
|
12
|
+
<th>Class</th>
|
13
|
+
<th>Args</th>
|
14
|
+
</tr>
|
15
|
+
<% for job in (jobs = resque.peek(queue, start, 20)) %>
|
16
|
+
<tr>
|
17
|
+
<td class='class'><%= job['class'] %></td>
|
18
|
+
<td class='args'><%=h job['args'].inspect %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
<% if jobs.empty? %>
|
22
|
+
<tr>
|
23
|
+
<td class='no-data' colspan='2'>There are no pending jobs in this queue</td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</table>
|
27
|
+
<%= partial :next_more, :start => start, :size => size %>
|
28
|
+
<% else %>
|
29
|
+
|
30
|
+
<h1 class='wi'>Queues</h1>
|
31
|
+
<p class='intro'>The list below contains all the registered queues with the number of jobs currently in the queue. Select a queue from above to view all jobs currently pending on the queue.</p>
|
32
|
+
<table class='queues'>
|
33
|
+
<tr>
|
34
|
+
<th>Name</th>
|
35
|
+
<th>Jobs</th>
|
36
|
+
</tr>
|
37
|
+
<% for queue in resque.queues.sort_by { |q| q.to_s } %>
|
38
|
+
<tr>
|
39
|
+
<td class='queue'><a class="queue" href="<%= u "queues/#{queue}" %>"><%= queue %></a></td>
|
40
|
+
<td class='size'><%= resque.size queue %></td>
|
41
|
+
</tr>
|
42
|
+
<% end %>
|
43
|
+
<tr class="<%= Resque::Failure.count.zero? ? "failed" : "failure" %>">
|
44
|
+
<td class='queue failed'><a class="queue" href="<%= u :failed %>">failed</a></td>
|
45
|
+
<td class='size'><%= Resque::Failure.count %></td>
|
46
|
+
</tr>
|
47
|
+
</table>
|
48
|
+
|
49
|
+
<% end %>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<% @subtabs = %w( resque redis keys ) %>
|
2
|
+
|
3
|
+
<% if params[:key] %>
|
4
|
+
|
5
|
+
<%= partial resque.redis.type(params[:key]).eql?("string") ? :key_string : :key_sets %>
|
6
|
+
|
7
|
+
<% elsif params[:id] == "resque" %>
|
8
|
+
|
9
|
+
<h1><%= resque %></h1>
|
10
|
+
<table class='stats'>
|
11
|
+
<% for key, value in resque.info.to_a.sort_by { |i| i[0].to_s } %>
|
12
|
+
<tr>
|
13
|
+
<th>
|
14
|
+
<%= key %>
|
15
|
+
</th>
|
16
|
+
<td>
|
17
|
+
<%= value %>
|
18
|
+
</td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<% elsif params[:id] == 'redis' %>
|
24
|
+
|
25
|
+
<h1><%= resque.redis_id %></h1>
|
26
|
+
<table class='stats'>
|
27
|
+
<% for key, value in resque.redis.info.to_a.sort_by { |i| i[0].to_s } %>
|
28
|
+
<tr>
|
29
|
+
<th>
|
30
|
+
<%= key %>
|
31
|
+
</th>
|
32
|
+
<td>
|
33
|
+
<%= value %>
|
34
|
+
</td>
|
35
|
+
</tr>
|
36
|
+
<% end %>
|
37
|
+
</table>
|
38
|
+
|
39
|
+
<% elsif params[:id] == 'keys' %>
|
40
|
+
|
41
|
+
<h1>Keys owned by <%= resque %></h1>
|
42
|
+
<p class='sub'>(All keys are actually prefixed with "<%= Resque.redis.namespace %>:")</p>
|
43
|
+
<table class='stats'>
|
44
|
+
<tr>
|
45
|
+
<th>key</th>
|
46
|
+
<th>type</th>
|
47
|
+
<th>size</th>
|
48
|
+
</tr>
|
49
|
+
<% for key in resque.keys.sort %>
|
50
|
+
<tr>
|
51
|
+
<th>
|
52
|
+
<a href="<%=u "/stats/keys/#{key}" %>"><%= key %></a>
|
53
|
+
</th>
|
54
|
+
<td><%= resque.redis.type key %></td>
|
55
|
+
<td><%= redis_get_size key %></td>
|
56
|
+
</tr>
|
57
|
+
<% end %>
|
58
|
+
</table>
|
59
|
+
|
60
|
+
<% else %>
|
61
|
+
|
62
|
+
<% end %>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
<% @subtabs = worker_hosts.keys.sort unless worker_hosts.size == 1 %>
|
2
|
+
|
3
|
+
<% if params[:id] && worker = Resque::Worker.find(params[:id]) %>
|
4
|
+
|
5
|
+
<h1>Worker <%= worker %></h1>
|
6
|
+
<table class='workers'>
|
7
|
+
<tr>
|
8
|
+
<th> </th>
|
9
|
+
<th>Host</th>
|
10
|
+
<th>Pid</th>
|
11
|
+
<th>Started</th>
|
12
|
+
<th>Queues</th>
|
13
|
+
<th>Processed</th>
|
14
|
+
<th>Failed</th>
|
15
|
+
<th>Processing</th>
|
16
|
+
</tr>
|
17
|
+
<tr>
|
18
|
+
<td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
|
19
|
+
|
20
|
+
<% host, pid, queues = worker.to_s.split(':') %>
|
21
|
+
<td><%= host %></td>
|
22
|
+
<td><%= pid %></td>
|
23
|
+
<td><span class="time"><%= worker.started %></span></td>
|
24
|
+
<td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
|
25
|
+
<td><%= worker.processed %></td>
|
26
|
+
<td><%= worker.failed %></td>
|
27
|
+
<td class='process'>
|
28
|
+
<% data = worker.processing || {} %>
|
29
|
+
<% if data['queue'] %>
|
30
|
+
<code><%= data['payload']['class'] %></code>
|
31
|
+
<small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
|
32
|
+
<% else %>
|
33
|
+
<span class='waiting'>Waiting for a job...</span>
|
34
|
+
<% end %>
|
35
|
+
</td>
|
36
|
+
</tr>
|
37
|
+
</table>
|
38
|
+
|
39
|
+
<% elsif params[:id] && !worker_hosts.keys.include?(params[:id]) && params[:id] != 'all' %>
|
40
|
+
|
41
|
+
<h1>Worker doesn't exist</h1>
|
42
|
+
|
43
|
+
<% elsif worker_hosts.size == 1 || params[:id] %>
|
44
|
+
|
45
|
+
<% if worker_hosts.size == 1 || params[:id] == 'all' %>
|
46
|
+
<% workers = Resque.workers %>
|
47
|
+
<% else %>
|
48
|
+
<% workers = worker_hosts[params[:id]].map { |id| Resque::Worker.find(id) } %>
|
49
|
+
<% end %>
|
50
|
+
|
51
|
+
<h1 class='wi'><%= workers.size %> Workers</h1>
|
52
|
+
<p class='intro'>The workers listed below are all registered as active on your system.</p>
|
53
|
+
<table class='workers'>
|
54
|
+
<tr>
|
55
|
+
<th> </th>
|
56
|
+
<th>Where</th>
|
57
|
+
<th>Queues</th>
|
58
|
+
<th>Processing</th>
|
59
|
+
</tr>
|
60
|
+
<% for worker in (workers = workers.sort_by { |w| w.to_s }) %>
|
61
|
+
<tr class="<%=state = worker.state%>">
|
62
|
+
<td class='icon'><img src="<%=u state %>.png" alt="<%= state %>" title="<%= state %>"></td>
|
63
|
+
|
64
|
+
<% host, pid, queues = worker.to_s.split(':') %>
|
65
|
+
<td class='where'><a href="<%=u "workers/#{worker}"%>"><%= host %>:<%= pid %></a></td>
|
66
|
+
<td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
|
67
|
+
|
68
|
+
<td class='process'>
|
69
|
+
<% data = worker.processing || {} %>
|
70
|
+
<% if data['queue'] %>
|
71
|
+
<code><%= data['payload']['class'] %></code>
|
72
|
+
<small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
|
73
|
+
<% else %>
|
74
|
+
<span class='waiting'>Waiting for a job...</span>
|
75
|
+
<% end %>
|
76
|
+
</td>
|
77
|
+
</tr>
|
78
|
+
<% end %>
|
79
|
+
<% if workers.empty? %>
|
80
|
+
<tr>
|
81
|
+
<td colspan='4' class='no-data'>There are no registered workers</td>
|
82
|
+
</tr>
|
83
|
+
<% end %>
|
84
|
+
</table>
|
85
|
+
<%=poll%>
|
86
|
+
|
87
|
+
<% else %>
|
88
|
+
<% @subtabs = [] %>
|
89
|
+
<h1 class='wi'>Workers</h1>
|
90
|
+
<p class='intro'>The hostnames below all have registered workers. Select a hostname to view its workers, or "all" to see all workers.</p>
|
91
|
+
<table class='queues'>
|
92
|
+
<tr>
|
93
|
+
<th>Hostname</th>
|
94
|
+
<th>Workers</th>
|
95
|
+
</tr>
|
96
|
+
<% for hostname, workers in worker_hosts.sort_by { |h,w| h } %>
|
97
|
+
<tr>
|
98
|
+
<td class='queue'><a class="queue" href="<%= u "workers/#{hostname}" %>"><%= hostname %></a></td>
|
99
|
+
<td class='size'><%= workers.size %></td>
|
100
|
+
</tr>
|
101
|
+
<% end %>
|
102
|
+
<tr class="failed">
|
103
|
+
<td class='queue failed'><a class="queue" href="<%= u "workers/all" %>">all workers</a></td>
|
104
|
+
<td class='size'><%= Resque.workers.size %></td>
|
105
|
+
</tr>
|
106
|
+
</table>
|
107
|
+
|
108
|
+
|
109
|
+
<% end %>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
<% if params[:id] && (worker = Resque::Worker.find(params[:id])) && worker.job %>
|
2
|
+
<h1><%= worker %>'s job</h1>
|
3
|
+
|
4
|
+
<table>
|
5
|
+
<tr>
|
6
|
+
<th> </th>
|
7
|
+
<th>Where</th>
|
8
|
+
<th>Queue</th>
|
9
|
+
<th>Started</th>
|
10
|
+
<th>Class</th>
|
11
|
+
<th>Args</th>
|
12
|
+
</tr>
|
13
|
+
<tr>
|
14
|
+
<td><img src="<%=u 'working.png' %>" alt="working" title="working"></td>
|
15
|
+
<% host, pid, _ = worker.to_s.split(':') %>
|
16
|
+
<td><a href="<%=u "/workers/#{worker}" %>"><%= host %>:<%= pid %></a></td>
|
17
|
+
<% data = worker.job %>
|
18
|
+
<% queue = data['queue'] %>
|
19
|
+
<td><a class="queue" href="<%=u "/queues/#{queue}" %>"><%= queue %></a></td>
|
20
|
+
<td><span class="time"><%= data['run_at'] %></span></td>
|
21
|
+
<td>
|
22
|
+
<code><%= data['payload']['class'] %></code>
|
23
|
+
</td>
|
24
|
+
<td><%=h data['payload']['args'].inspect %></td>
|
25
|
+
</tr>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<% else %>
|
29
|
+
|
30
|
+
<%
|
31
|
+
workers = resque.working
|
32
|
+
jobs = workers.collect {|w| w.job }
|
33
|
+
worker_jobs = workers.zip(jobs)
|
34
|
+
worker_jobs = worker_jobs.reject { |w, j| w.idle? }
|
35
|
+
%>
|
36
|
+
|
37
|
+
<h1 class='wi'><%= worker_jobs.size %> of <%= resque.workers.size %> Workers Working</h1>
|
38
|
+
<p class='intro'>The list below contains all workers which are currently running a job.</p>
|
39
|
+
<table class='workers'>
|
40
|
+
<tr>
|
41
|
+
<th> </th>
|
42
|
+
<th>Where</th>
|
43
|
+
<th>Queue</th>
|
44
|
+
<th>Processing</th>
|
45
|
+
</tr>
|
46
|
+
<% if worker_jobs.empty? %>
|
47
|
+
<tr>
|
48
|
+
<td colspan="4" class='no-data'>Nothing is happening right now...</td>
|
49
|
+
</tr>
|
50
|
+
<% end %>
|
51
|
+
|
52
|
+
<% worker_jobs.sort_by {|w, j| j['run_at'] ? j['run_at'] : '' }.each do |worker, job| %>
|
53
|
+
<tr>
|
54
|
+
<td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
|
55
|
+
<% host, pid, queues = worker.to_s.split(':') %>
|
56
|
+
<td class='where'><a href="<%=u "/workers/#{worker}" %>"><%= host %>:<%= pid %></a></td>
|
57
|
+
<td class='queues queue'>
|
58
|
+
<a class="queue-tag" href="<%=u "/queues/#{job['queue']}" %>"><%= job['queue'] %></a>
|
59
|
+
</td>
|
60
|
+
<td class='process'>
|
61
|
+
<% if job['queue'] %>
|
62
|
+
<code><%= job['payload']['class'] %></code>
|
63
|
+
<small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= job['run_at'] %></a></small>
|
64
|
+
<% else %>
|
65
|
+
<span class='waiting'>Waiting for a job...</span>
|
66
|
+
<% end %>
|
67
|
+
</td>
|
68
|
+
</tr>
|
69
|
+
<% end %>
|
70
|
+
</table>
|
71
|
+
|
72
|
+
<% end %>
|
data/lib/resque/stat.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Resque
|
2
|
+
# The stat subsystem. Used to keep track of integer counts.
|
3
|
+
#
|
4
|
+
# Get a stat: Stat[name]
|
5
|
+
# Incr a stat: Stat.incr(name)
|
6
|
+
# Decr a stat: Stat.decr(name)
|
7
|
+
# Kill a stat: Stat.clear(name)
|
8
|
+
module Stat
|
9
|
+
extend self
|
10
|
+
extend Helpers
|
11
|
+
|
12
|
+
# Returns the int value of a stat, given a string stat name.
|
13
|
+
def get(stat)
|
14
|
+
redis.get("stat:#{stat}").to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
# Alias of `get`
|
18
|
+
def [](stat)
|
19
|
+
get(stat)
|
20
|
+
end
|
21
|
+
|
22
|
+
# For a string stat name, increments the stat by one.
|
23
|
+
#
|
24
|
+
# Can optionally accept a second int parameter. The stat is then
|
25
|
+
# incremented by that amount.
|
26
|
+
def incr(stat, by = 1)
|
27
|
+
redis.incrby("stat:#{stat}", by)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Increments a stat by one.
|
31
|
+
def <<(stat)
|
32
|
+
incr stat
|
33
|
+
end
|
34
|
+
|
35
|
+
# For a string stat name, decrements the stat by one.
|
36
|
+
#
|
37
|
+
# Can optionally accept a second int parameter. The stat is then
|
38
|
+
# decremented by that amount.
|
39
|
+
def decr(stat, by = 1)
|
40
|
+
redis.decrby("stat:#{stat}", by)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Decrements a stat by one.
|
44
|
+
def >>(stat)
|
45
|
+
decr stat
|
46
|
+
end
|
47
|
+
|
48
|
+
# Removes a stat from Redis, effectively setting it to 0.
|
49
|
+
def clear(stat)
|
50
|
+
redis.del("stat:#{stat}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/resque/tasks.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# require 'resque/tasks'
|
2
|
+
# will give you the resque tasks
|
3
|
+
|
4
|
+
namespace :resque do
|
5
|
+
task :setup
|
6
|
+
|
7
|
+
desc "Start a Resque worker"
|
8
|
+
task :work => [ :preload, :setup ] do
|
9
|
+
require 'resque'
|
10
|
+
|
11
|
+
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
|
12
|
+
|
13
|
+
begin
|
14
|
+
worker = Resque::Worker.new(*queues)
|
15
|
+
worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
|
16
|
+
worker.very_verbose = ENV['VVERBOSE']
|
17
|
+
rescue Resque::NoQueueError
|
18
|
+
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
|
19
|
+
end
|
20
|
+
|
21
|
+
if ENV['BACKGROUND']
|
22
|
+
unless Process.respond_to?('daemon')
|
23
|
+
abort "env var BACKGROUND is set, which requires ruby >= 1.9"
|
24
|
+
end
|
25
|
+
Process.daemon(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
if ENV['PIDFILE']
|
29
|
+
File.open(ENV['PIDFILE'], 'w') { |f| f << worker.pid }
|
30
|
+
end
|
31
|
+
|
32
|
+
worker.log "Starting worker #{worker}"
|
33
|
+
|
34
|
+
worker.work(ENV['INTERVAL'] || 5) # interval, will block
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Start multiple Resque workers. Should only be used in dev mode."
|
38
|
+
task :workers do
|
39
|
+
threads = []
|
40
|
+
|
41
|
+
ENV['COUNT'].to_i.times do
|
42
|
+
threads << Thread.new do
|
43
|
+
system "rake resque:work"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
threads.each { |thread| thread.join }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Preload app files if this is Rails
|
51
|
+
task :preload => :setup do
|
52
|
+
if defined?(Rails) && Rails.respond_to?(:application)
|
53
|
+
# Rails 3
|
54
|
+
Rails.application.eager_load!
|
55
|
+
elsif defined?(Rails::Initializer)
|
56
|
+
# Rails 2.3
|
57
|
+
$rails_rake_task = false
|
58
|
+
Rails::Initializer.run :load_application_classes
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|