resque-mongo 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +3 -0
  2. data/.kick +26 -0
  3. data/CONTRIBUTORS +14 -0
  4. data/HISTORY.md +53 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +755 -0
  7. data/Rakefile +65 -0
  8. data/bin/resque +57 -0
  9. data/bin/resque-web +18 -0
  10. data/config.ru +14 -0
  11. data/deps.rip +8 -0
  12. data/examples/async_helper.rb +31 -0
  13. data/examples/demo/README.markdown +71 -0
  14. data/examples/demo/Rakefile +3 -0
  15. data/examples/demo/app.rb +27 -0
  16. data/examples/demo/config.ru +19 -0
  17. data/examples/demo/job.rb +12 -0
  18. data/examples/god/resque.god +52 -0
  19. data/examples/god/stale.god +26 -0
  20. data/examples/instance.rb +11 -0
  21. data/examples/simple.rb +30 -0
  22. data/init.rb +1 -0
  23. data/lib/resque.rb +224 -0
  24. data/lib/resque/errors.rb +7 -0
  25. data/lib/resque/failure.rb +63 -0
  26. data/lib/resque/failure/base.rb +58 -0
  27. data/lib/resque/failure/hoptoad.rb +88 -0
  28. data/lib/resque/failure/mongo.rb +32 -0
  29. data/lib/resque/helpers.rb +65 -0
  30. data/lib/resque/job.rb +103 -0
  31. data/lib/resque/server.rb +182 -0
  32. data/lib/resque/server/public/idle.png +0 -0
  33. data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
  34. data/lib/resque/server/public/jquery.relatize_date.js +95 -0
  35. data/lib/resque/server/public/poll.png +0 -0
  36. data/lib/resque/server/public/ranger.js +24 -0
  37. data/lib/resque/server/public/reset.css +48 -0
  38. data/lib/resque/server/public/style.css +75 -0
  39. data/lib/resque/server/public/working.png +0 -0
  40. data/lib/resque/server/views/error.erb +1 -0
  41. data/lib/resque/server/views/failed.erb +35 -0
  42. data/lib/resque/server/views/key.erb +17 -0
  43. data/lib/resque/server/views/layout.erb +38 -0
  44. data/lib/resque/server/views/next_more.erb +10 -0
  45. data/lib/resque/server/views/overview.erb +4 -0
  46. data/lib/resque/server/views/queues.erb +46 -0
  47. data/lib/resque/server/views/stats.erb +62 -0
  48. data/lib/resque/server/views/workers.erb +78 -0
  49. data/lib/resque/server/views/working.erb +67 -0
  50. data/lib/resque/stat.rb +55 -0
  51. data/lib/resque/tasks.rb +39 -0
  52. data/lib/resque/version.rb +3 -0
  53. data/lib/resque/worker.rb +415 -0
  54. data/tasks/redis.rake +133 -0
  55. data/tasks/resque.rake +2 -0
  56. data/test/dump.rdb +0 -0
  57. data/test/redis-test.conf +132 -0
  58. data/test/resque_test.rb +191 -0
  59. data/test/test_helper.rb +87 -0
  60. data/test/worker_test.rb +229 -0
  61. metadata +162 -0
@@ -0,0 +1,24 @@
1
+ var poll_interval = 2;
2
+
3
+ $(function() {
4
+
5
+ $('.time').relatizeDate()
6
+ $('.backtrace').click(function() {
7
+ $(this).next().toggle()
8
+ return false
9
+ })
10
+
11
+ $('a[rel=poll]').click(function() {
12
+ var href = $(this).attr('href')
13
+ $(this).parent().text('Starting...')
14
+ $("#main").addClass('polling')
15
+ setInterval(function() {
16
+ $.ajax({dataType:'text', type:'get', url:href, success:function(data) {
17
+ $('#main').html(data)
18
+ $('#main .time').relatizeDate()
19
+ }})
20
+ }, poll_interval * 1000)
21
+ return false
22
+ })
23
+
24
+ })
@@ -0,0 +1,48 @@
1
+ html, body, div, span, applet, object, iframe,
2
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
3
+ a, abbr, acronym, address, big, cite, code,
4
+ del, dfn, em, font, img, ins, kbd, q, s, samp,
5
+ small, strike, strong, sub, sup, tt, var,
6
+ dl, dt, dd, ul, li,
7
+ form, label, legend,
8
+ table, caption, tbody, tfoot, thead, tr, th, td {
9
+ margin: 0;
10
+ padding: 0;
11
+ border: 0;
12
+ outline: 0;
13
+ font-weight: inherit;
14
+ font-style: normal;
15
+ font-size: 100%;
16
+ font-family: inherit;
17
+ }
18
+
19
+ :focus {
20
+ outline: 0;
21
+ }
22
+
23
+ body {
24
+ line-height: 1;
25
+ }
26
+
27
+ ul {
28
+ list-style: none;
29
+ }
30
+
31
+ table {
32
+ border-collapse: collapse;
33
+ border-spacing: 0;
34
+ }
35
+
36
+ caption, th, td {
37
+ text-align: left;
38
+ font-weight: normal;
39
+ }
40
+
41
+ blockquote:before, blockquote:after,
42
+ q:before, q:after {
43
+ content: "";
44
+ }
45
+
46
+ blockquote, q {
47
+ quotes: "" "";
48
+ }
@@ -0,0 +1,75 @@
1
+ html { background:#efefef; font-family:Arial, Verdana, sans-serif; font-size:13px; }
2
+ body { padding:0; margin:0; }
3
+
4
+ .header { background:#000; padding:8px 5% 0 5%; border-bottom:1px solid #444;border-bottom:5px solid #ce1212;}
5
+ .header h1 { color:#333; font-size:90%; font-weight:bold; margin-bottom:6px;}
6
+ .header ul li { display:inline;}
7
+ .header ul li a { color:#fff; text-decoration:none; margin-right:10px; display:inline-block; padding:8px; -webkit-border-top-right-radius:6px; -webkit-border-top-left-radius:6px; }
8
+ .header ul li a:hover { background:#333;}
9
+ .header ul li.current a { background:#ce1212; font-weight:bold; color:#fff;}
10
+
11
+ .subnav { padding:2px 5% 7px 5%; background:#ce1212; font-size:90%;}
12
+ .subnav li { display:inline;}
13
+ .subnav li a { color:#fff; text-decoration:none; margin-right:10px; display:inline-block; background:#dd5b5b; padding:5px; -webkit-border-radius:3px; -moz-border-radius:3px;}
14
+ .subnav li.current a { background:#fff; font-weight:bold; color:#ce1212;}
15
+ .subnav li a:active { background:#b00909;}
16
+
17
+ #main { padding:10px 5%; background:#fff; overflow:hidden; }
18
+ #main .logo { float:right; margin:10px;}
19
+ #main span.hl { background:#efefef; padding:2px;}
20
+ #main h1 { margin:10px 0; font-size:190%; font-weight:bold; color:#ce1212;}
21
+ #main h2 { margin:10px 0; font-size:130%;}
22
+ #main table { width:100%; margin:10px 0;}
23
+ #main table tr td, #main table tr th { border:1px solid #ccc; padding:6px;}
24
+ #main table tr th { background:#efefef; color:#888; font-size:80%; font-weight:bold;}
25
+ #main table tr td.no-data { text-align:center; padding:40px 0; color:#999; font-style:italic; font-size:130%;}
26
+ #main a { color:#111;}
27
+ #main p { margin:5px 0;}
28
+ #main p.intro { margin-bottom:15px; font-size:85%; color:#999; margin-top:0; line-height:1.3;}
29
+ #main h1.wi { margin-bottom:5px;}
30
+ #main p.sub { font-size:95%; color:#999;}
31
+
32
+ #main table.queues { width:40%;}
33
+ #main table.queues td.queue { font-weight:bold; width:50%;}
34
+ #main table.queues tr.failed td { background:#ffecec; border-top:2px solid #d37474; font-size:90%; color:#d37474;}
35
+ #main table.queues tr.failed td a{ color:#d37474;}
36
+
37
+ #main table.jobs td.class { font-family:Monaco, "Courier New", monospace; font-size:90%; width:50%;}
38
+ #main table.jobs td.args{ width:50%;}
39
+
40
+ #main table.workers td.icon {width:1%; background:#efefef;text-align:center;}
41
+ #main table.workers td.where { width:25%;}
42
+ #main table.workers td.queues { width:35%;}
43
+ #main .queue-tag { background:#b1d2e9; padding:2px; margin:0 3px; font-size:80%; text-decoration:none; text-transform:uppercase; font-weight:bold; color:#3274a2; -webkit-border-radius:4px; -moz-border-radius:4px;}
44
+ #main table.workers td.queues.queue { width:10%;}
45
+ #main table.workers td.process { width:35%;}
46
+ #main table.workers td.process span.waiting { color:#999; font-size:90%;}
47
+ #main table.workers td.process small { font-size:80%; margin-left:5px;}
48
+ #main table.workers td.process code { font-family:Monaco, "Courier New", monospace; font-size:90%;}
49
+ #main table.workers td.process small a { color:#999;}
50
+ #main.polling table.workers tr.working td { background:#f4ffe4; color:#7ac312;}
51
+ #main.polling table.workers tr.working td.where a { color:#7ac312;}
52
+ #main.polling table.workers tr.working td.process code { font-weight:bold;}
53
+
54
+
55
+ #main table.stats th { font-size:100%; width:40%; color:#000;}
56
+ #main hr { border:0; border-top:5px solid #efefef; margin:15px 0;}
57
+
58
+ #footer { padding:10px 5%; background:#efefef; color:#999; font-size:85%; line-height:1.5; border-top:5px solid #ccc; padding-top:10px;}
59
+ #footer p a { color:#999;}
60
+
61
+ #main p.poll { background:url(poll.png) no-repeat 0 2px; padding:3px 0; padding-left:23px; float:right; font-size:85%; }
62
+
63
+ #main ul.failed {}
64
+ #main ul.failed li {background:-webkit-gradient(linear, left top, left bottom, from(#efefef), to(#fff)) #efefef; margin-top:10px; padding:10px; overflow:hidden; -webkit-border-radius:5px; border:1px solid #ccc; }
65
+ #main ul.failed li dl dt {font-size:80%; color:#999; width:60px; float:left; padding-top:1px; text-align:right;}
66
+ #main ul.failed li dl dd {margin-bottom:10px; margin-left:70px;}
67
+ #main ul.failed li dl dd code, #main ul.failed li dl dd pre { font-family:Monaco, "Courier New", monospace; font-size:90%;}
68
+ #main ul.failed li dl dd.error a {font-family:Monaco, "Courier New", monospace; font-size:90%; }
69
+ #main ul.failed li dl dd.error pre { margin-top:3px; line-height:1.3;}
70
+
71
+ #main p.pagination { background:#efefef; padding:10px; overflow:hidden;}
72
+ #main p.pagination a.less { float:left;}
73
+ #main p.pagination a.more { float:right;}
74
+
75
+ #main form.clear-failed {float:right; margin-top:-10px;}
@@ -0,0 +1 @@
1
+ <h1 style="font-size:110%;font-family:Arial, sans-serif;"><%= error %></h1>
@@ -0,0 +1,35 @@
1
+ <%start = params[:start].to_i %>
2
+ <%failed = Resque::Failure.all(start, 20)%>
3
+
4
+ <h1>Failed Jobs</h1>
5
+ <%unless failed.empty?%>
6
+ <form method="POST" action="<%=u 'failed/clear'%>" class='clear-failed'>
7
+ <input type='submit' name='' value='Clear Failed Jobs' />
8
+ </form>
9
+ <%end%>
10
+
11
+ <p class='sub'>Showing <%=start%> to <%= start + 20 %> of <b><%= size = Resque::Failure.count %></b> jobs</p>
12
+
13
+ <ul class='failed'>
14
+ <%for job in failed%>
15
+ <li>
16
+ <dl>
17
+ <dt>Worker</dt>
18
+ <dd><a href="<%= url(:workers, job['worker']) %>"><%= job['worker'].split(':')[0...2].join(':') %></a> on <b class='queue-tag'><%= job['queue'] %></b > at <b><span class="time"><%= job['failed_at'] %></span></b></dd>
19
+ <dt>Class</dt>
20
+ <dd><code><%= job['payload']['class'] %></code></dd>
21
+ <dt>Arguments</dt>
22
+ <dd><pre><%=h show_args(job['payload']['args']) %></pre></dd>
23
+ <dt>Error</dt>
24
+ <dd class='error'>
25
+ <a href="#" class="backtrace"><%= h(job['error']) %></a>
26
+ <pre style='display:none'><%=h job['backtrace'].join("\n") %></pre>
27
+ </dd>
28
+ </dl>
29
+ <div class='r'>
30
+ </div>
31
+ </li>
32
+ <%end%>
33
+ </ul>
34
+
35
+ <%= partial :next_more, :start => start, :size => size %>
@@ -0,0 +1,17 @@
1
+ <% if key = params[:key] %>
2
+
3
+ <h1>Key "<%= key %>" is a <%= resque.redis.type key %></h1>
4
+ <h2>size: <%= redis_get_size(key) %></h2>
5
+ <table>
6
+ <% for row in redis_get_value_as_array(key) %>
7
+ <tr>
8
+ <td>
9
+ <%= row %>
10
+ </td>
11
+ </tr>
12
+ <% end %>
13
+ </table>
14
+
15
+ <% else %>
16
+
17
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Resque.</title>
5
+ <link href="<%=u 'reset.css' %>" media="screen" rel="stylesheet" type="text/css">
6
+ <link href="<%=u 'style.css' %>" media="screen" rel="stylesheet" type="text/css">
7
+ <script src="<%=u 'jquery-1.3.2.min.js' %>" type="text/javascript"</script>
8
+ <script src="<%=u 'jquery.relatize_date.js' %>" type="text/javascript"</script>
9
+ <script src="<%=u 'ranger.js' %>" type="text/javascript"></script>
10
+ </head>
11
+ <body>
12
+ <div class="header">
13
+ <ul class='nav'>
14
+ <% tabs.each do |tab_name| %>
15
+ <%= tab tab_name %>
16
+ <% end %>
17
+ </ul>
18
+ </div>
19
+
20
+ <% if @subtabs %>
21
+ <ul class='subnav'>
22
+ <% for subtab in @subtabs %>
23
+ <li <%= class_if_current "#{current_section}/#{subtab}" %>><a href="<%= current_section %>/<%= subtab %>"><span><%= subtab %></span></a></li>
24
+ <% end %>
25
+ </ul>
26
+ <% end %>
27
+
28
+ <div id="main">
29
+ <%= yield %>
30
+ </div>
31
+
32
+ <div id="footer">
33
+ <p>Powered by <a href="http://github.com/defunkt/resque">Resque</a> v<%=Resque::Version%></p>
34
+ <p>Connected to Redis on ... </p>
35
+ </div>
36
+
37
+ </body>
38
+ </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'>&laquo; less</a>
5
+ <% end %>
6
+ <% if start + 20 <= size %>
7
+ <a href="<%= current_page %>?start=<%= start + 20 %>" class='more'>more &raquo;</a>
8
+ <% end %>
9
+ </p>
10
+ <%end%>
@@ -0,0 +1,4 @@
1
+ <%= partial :queues %>
2
+ <hr />
3
+ <%= partial :working %>
4
+ <%= poll %>
@@ -0,0 +1,46 @@
1
+ <% @subtabs = resque.queues unless partial? %>
2
+
3
+ <% if queue = params[:id] %>
4
+
5
+ <h1>Pending jobs on <span class='hl'><%= queue %></span></h1>
6
+ <p class='sub'>Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = resque.size(queue)%></b> jobs</p>
7
+ <table class='jobs'>
8
+ <tr>
9
+ <th>Class</th>
10
+ <th>Args</th>
11
+ </tr>
12
+ <% for job in (jobs = resque.peek(queue, start, 20)) %>
13
+ <tr>
14
+ <td class='class'><%= job['class'] %></td>
15
+ <td class='args'><%=h job['args'].inspect %></td>
16
+ </tr>
17
+ <% end %>
18
+ <% if jobs.empty? %>
19
+ <tr>
20
+ <td class='no-data' colspan='2'>There are no pending jobs in this queue</td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+ <%= partial :next_more, :start => start, :size => size %>
25
+ <% else %>
26
+
27
+ <h1 class='wi'>Queues</h1>
28
+ <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>
29
+ <table class='queues'>
30
+ <tr>
31
+ <th>Name</th>
32
+ <th>Jobs</th>
33
+ </tr>
34
+ <% for queue in resque.queues.sort_by { |q| q.to_s } %>
35
+ <tr>
36
+ <td class='queue'><a class="queue" href="<%= url "queues/#{queue}" %>"><%= queue %></a></td>
37
+ <td class='size'><%= resque.size queue %></td>
38
+ </tr>
39
+ <% end %>
40
+ <tr class='failed'>
41
+ <td class='queue failed'><a class="queue" href="<%= url :failed %>">failed</a></td>
42
+ <td class='size'><%= Resque::Failure.count %></td>
43
+ </tr>
44
+ </table>
45
+
46
+ <% end %>
@@ -0,0 +1,62 @@
1
+ <% @subtabs = %w( resque redis keys ) %>
2
+
3
+ <% if params[:key] %>
4
+
5
+ <%= partial :key %>
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.server %></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:")</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,78 @@
1
+ <% if params[:id] && worker = Resque::Worker.find(params[:id]) %>
2
+
3
+ <h1>Worker <%= worker %></h1>
4
+ <table class='workers'>
5
+ <tr>
6
+ <th>&nbsp;</th>
7
+ <th>Host</th>
8
+ <th>Pid</th>
9
+ <th>Started</th>
10
+ <th>Queues</th>
11
+ <th>Processed</th>
12
+ <th>Failed</th>
13
+ <th>Processing</th>
14
+ </tr>
15
+ <tr>
16
+ <td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
17
+
18
+ <% host, pid, queues = worker.to_s.split(':') %>
19
+ <td><%= host %></td>
20
+ <td><%= pid %></td>
21
+ <td><span class="time"><%= worker.started %></a></td>
22
+ <td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
23
+ <td><%= worker.processed %></td>
24
+ <td><%= worker.failed %></td>
25
+ <td class='process'>
26
+ <% data = worker.processing || {} %>
27
+ <% if data['queue'] %>
28
+ <code><%= data['payload']['class'] %></code>
29
+ <small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
30
+ <% else %>
31
+ <span class='waiting'>Waiting for a job...</span>
32
+ <% end %>
33
+ </td>
34
+ </tr>
35
+ </table>
36
+
37
+ <% elsif params[:id] %>
38
+
39
+ <h1>Worker doesn't exist</h1>
40
+
41
+ <% else %>
42
+
43
+ <h1 class='wi'><%= resque.workers.size %> Workers</h1>
44
+ <p class='intro'>The workers listed below are all registered as active on your system.</p>
45
+ <table class='workers'>
46
+ <tr>
47
+ <th>&nbsp;</th>
48
+ <th>Where</th>
49
+ <th>Queues</th>
50
+ <th>Processing</th>
51
+ </tr>
52
+ <% for worker in (workers = resque.workers.sort_by { |w| w.to_s }) %>
53
+ <tr class="<%=state = worker.state%>">
54
+ <td class='icon'><img src="<%=u state %>.png" alt="<%= state %>" title="<%= state %>"></td>
55
+
56
+ <% host, pid, queues = worker.to_s.split(':') %>
57
+ <td class='where'><a href="<%=u "workers/#{worker}"%>"><%= host %>:<%= pid %></a></td>
58
+ <td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
59
+
60
+ <td class='process'>
61
+ <% data = worker.processing || {} %>
62
+ <% if data['queue'] %>
63
+ <code><%= data['payload']['class'] %></code>
64
+ <small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
65
+ <% else %>
66
+ <span class='waiting'>Waiting for a job...</span>
67
+ <% end %>
68
+ </td>
69
+ </tr>
70
+ <% end %>
71
+ <% if workers.empty? %>
72
+ <tr>
73
+ <td colspan='4' class='no-data'>There are no registered workers</td>
74
+ </tr>
75
+ <% end %>
76
+ </table>
77
+ <%=poll%>
78
+ <% end %>