resque-igo 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/HISTORY.md +225 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +855 -0
  4. data/Rakefile +70 -0
  5. data/bin/resque +57 -0
  6. data/bin/resque-web +23 -0
  7. data/lib/resque.rb +380 -0
  8. data/lib/resque/errors.rb +10 -0
  9. data/lib/resque/failure.rb +66 -0
  10. data/lib/resque/failure/base.rb +61 -0
  11. data/lib/resque/failure/hoptoad.rb +132 -0
  12. data/lib/resque/failure/multiple.rb +50 -0
  13. data/lib/resque/failure/redis.rb +40 -0
  14. data/lib/resque/helpers.rb +71 -0
  15. data/lib/resque/job.rb +209 -0
  16. data/lib/resque/plugin.rb +51 -0
  17. data/lib/resque/server.rb +247 -0
  18. data/lib/resque/server/public/idle.png +0 -0
  19. data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
  20. data/lib/resque/server/public/jquery.relatize_date.js +95 -0
  21. data/lib/resque/server/public/poll.png +0 -0
  22. data/lib/resque/server/public/ranger.js +67 -0
  23. data/lib/resque/server/public/reset.css +48 -0
  24. data/lib/resque/server/public/style.css +86 -0
  25. data/lib/resque/server/public/working.png +0 -0
  26. data/lib/resque/server/test_helper.rb +19 -0
  27. data/lib/resque/server/views/error.erb +1 -0
  28. data/lib/resque/server/views/failed.erb +53 -0
  29. data/lib/resque/server/views/key_sets.erb +20 -0
  30. data/lib/resque/server/views/key_string.erb +11 -0
  31. data/lib/resque/server/views/layout.erb +42 -0
  32. data/lib/resque/server/views/next_more.erb +10 -0
  33. data/lib/resque/server/views/overview.erb +4 -0
  34. data/lib/resque/server/views/queues.erb +65 -0
  35. data/lib/resque/server/views/stats.erb +73 -0
  36. data/lib/resque/server/views/workers.erb +109 -0
  37. data/lib/resque/server/views/working.erb +68 -0
  38. data/lib/resque/stat.rb +54 -0
  39. data/lib/resque/tasks.rb +39 -0
  40. data/lib/resque/version.rb +3 -0
  41. data/lib/resque/worker.rb +478 -0
  42. data/tasks/resque.rake +2 -0
  43. data/test/job_hooks_test.rb +323 -0
  44. data/test/job_plugins_test.rb +230 -0
  45. data/test/plugin_test.rb +116 -0
  46. data/test/resque-web_test.rb +54 -0
  47. data/test/resque_test.rb +351 -0
  48. data/test/test_helper.rb +166 -0
  49. data/test/worker_test.rb +302 -0
  50. metadata +180 -0
@@ -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,86 @@
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; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; }
8
+ .header ul li a:hover { background:#333;}
9
+ .header ul li.current a { background:#ce1212; font-weight:bold; color:#fff;}
10
+
11
+ .header .namespace { position: absolute; right: 75px; top: 10px; color: #7A7A7A; }
12
+
13
+ .subnav { padding:2px 5% 7px 5%; background:#ce1212; font-size:90%;}
14
+ .subnav li { display:inline;}
15
+ .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;}
16
+ .subnav li.current a { background:#fff; font-weight:bold; color:#ce1212;}
17
+ .subnav li a:active { background:#b00909;}
18
+
19
+ #main { padding:10px 5%; background:#fff; overflow:hidden; }
20
+ #main .logo { float:right; margin:10px;}
21
+ #main span.hl { background:#efefef; padding:2px;}
22
+ #main h1 { margin:10px 0; font-size:190%; font-weight:bold; color:#ce1212;}
23
+ #main h2 { margin:10px 0; font-size:130%;}
24
+ #main table { width:100%; margin:10px 0;}
25
+ #main table tr td, #main table tr th { border:1px solid #ccc; padding:6px;}
26
+ #main table tr th { background:#efefef; color:#888; font-size:80%; font-weight:bold;}
27
+ #main table tr td.no-data { text-align:center; padding:40px 0; color:#999; font-style:italic; font-size:130%;}
28
+ #main a { color:#111;}
29
+ #main p { margin:5px 0;}
30
+ #main p.intro { margin-bottom:15px; font-size:85%; color:#999; margin-top:0; line-height:1.3;}
31
+ #main h1.wi { margin-bottom:5px;}
32
+ #main p.sub { font-size:95%; color:#999;}
33
+
34
+ #main table.queues { width:40%;}
35
+ #main table.queues td.queue { font-weight:bold; width:50%;}
36
+ #main table.queues tr.failed td { border-top:2px solid; font-size:90%; }
37
+ #main table.queues tr.failure td { background:#ffecec; border-top:2px solid #d37474; font-size:90%; color:#d37474;}
38
+ #main table.queues tr.failure td a{ color:#d37474;}
39
+
40
+ #main table.jobs td.class { font-family:Monaco, "Courier New", monospace; font-size:90%; width:50%;}
41
+ #main table.jobs td.args{ width:50%;}
42
+
43
+ #main table.delays td.class { font-family:Monaco, "Courier New", monospace; font-size:90%; width:20%;}
44
+ #main table.delays td.args{ width:40%;}
45
+ #main table.delays td.delay{ width:40%;}
46
+
47
+
48
+ #main table.workers td.icon {width:1%; background:#efefef;text-align:center;}
49
+ #main table.workers td.where { width:25%;}
50
+ #main table.workers td.queues { width:35%;}
51
+ #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;}
52
+ #main table.workers td.queues.queue { width:10%;}
53
+ #main table.workers td.process { width:35%;}
54
+ #main table.workers td.process span.waiting { color:#999; font-size:90%;}
55
+ #main table.workers td.process small { font-size:80%; margin-left:5px;}
56
+ #main table.workers td.process code { font-family:Monaco, "Courier New", monospace; font-size:90%;}
57
+ #main table.workers td.process small a { color:#999;}
58
+ #main.polling table.workers tr.working td { background:#f4ffe4; color:#7ac312;}
59
+ #main.polling table.workers tr.working td.where a { color:#7ac312;}
60
+ #main.polling table.workers tr.working td.process code { font-weight:bold;}
61
+
62
+
63
+ #main table.stats th { font-size:100%; width:40%; color:#000;}
64
+ #main hr { border:0; border-top:5px solid #efefef; margin:15px 0;}
65
+
66
+ #footer { padding:10px 5%; background:#efefef; color:#999; font-size:85%; line-height:1.5; border-top:5px solid #ccc; padding-top:10px;}
67
+ #footer p a { color:#999;}
68
+
69
+ #main p.poll { background:url(poll.png) no-repeat 0 2px; padding:3px 0; padding-left:23px; float:right; font-size:85%; }
70
+
71
+ #main ul.failed {}
72
+ #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; }
73
+ #main ul.failed li dl dt {font-size:80%; color:#999; width:60px; float:left; padding-top:1px; text-align:right;}
74
+ #main ul.failed li dl dd {margin-bottom:10px; margin-left:70px;}
75
+ #main ul.failed li dl dd .retry { float: right; }
76
+ #main ul.failed li dl dd code, #main ul.failed li dl dd pre { font-family:Monaco, "Courier New", monospace; font-size:90%;}
77
+ #main ul.failed li dl dd.error a {font-family:Monaco, "Courier New", monospace; font-size:90%; }
78
+ #main ul.failed li dl dd.error pre { margin-top:3px; line-height:1.3;}
79
+
80
+ #main p.pagination { background:#efefef; padding:10px; overflow:hidden;}
81
+ #main p.pagination a.less { float:left;}
82
+ #main p.pagination a.more { float:right;}
83
+
84
+ #main form {float:right; margin-top:-10px;}
85
+
86
+ #main .time a.toggle_format {text-decoration:none;}
@@ -0,0 +1,19 @@
1
+ require 'rack/test'
2
+ require 'resque/server'
3
+
4
+ module Resque
5
+ module TestHelper
6
+ class Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+ def app
9
+ Resque::Server.new
10
+ end
11
+
12
+ def self.should_respond_with_success
13
+ test "should respond with success" do
14
+ assert last_response.ok?, last_response.errors
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ <h1 style="font-size:110%;font-family:Arial, sans-serif;"><%= error %></h1>
@@ -0,0 +1,53 @@
1
+ <%start = params[:start].to_i %>
2
+ <%failed = Resque::Failure.all(start, 20)%>
3
+ <% index = 0 %>
4
+
5
+ <h1>Failed Jobs</h1>
6
+ <%unless failed.empty?%>
7
+ <form method="POST" action="<%=u 'failed/clear'%>" class='clear-failed'>
8
+ <input type='submit' name='' value='Clear Failed Jobs' />
9
+ </form>
10
+ <%end%>
11
+
12
+ <p class='sub'>Showing <%=start%> to <%= start + 20 %> of <b><%= size = Resque::Failure.count %></b> jobs</p>
13
+
14
+ <ul class='failed'>
15
+ <%for job in failed%>
16
+ <% index += 1 %>
17
+ <li>
18
+ <dl>
19
+ <dt>Worker</dt>
20
+ <dd>
21
+ <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>
22
+ <div class='retry'>
23
+ <% if job['retried_at'] %>
24
+ Retried <b><span class="time"><%= job['retried_at'] %></span></b>
25
+ <% else %>
26
+ <a href="<%= u "failed/requeue/#{start + index - 1}" %>" rel="retry">Retry</a>
27
+ <% end %>
28
+ </div>
29
+ </dd>
30
+ <dt>Class</dt>
31
+ <dd><code><%= job['payload'] ? job['payload']['class'] : 'nil' %></code></dd>
32
+ <dt>Arguments</dt>
33
+ <dd><pre><%=h job['payload'] ? show_args(job['payload']['args']) : 'nil' %></pre></dd>
34
+ <dt>Exception</td>
35
+ <dd><code><%= job['exception'] %></code></dd>
36
+ <dt>Error</dt>
37
+ <dd class='error'>
38
+ <% if job['backtrace'] %>
39
+ <a href="#" class="backtrace"><%= h(job['error']) %></a>
40
+ <pre style='display:none'><%=h job['backtrace'].join("\n") %></pre>
41
+ <% else %>
42
+ <%=h job['error'] %>
43
+ <% end %>
44
+ </dd>
45
+ </dl>
46
+ <div class='r'>
47
+ </div>
48
+ </li>
49
+ <%end%>
50
+ </ul>
51
+
52
+ <%= partial :next_more, :start => start, :size => size %>
53
+
@@ -0,0 +1,20 @@
1
+ <% if key = params[:key] %>
2
+
3
+ <p class='sub'>
4
+ Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = mongo_get_size(key) %></b>
5
+ </p>
6
+
7
+
8
+ <h1>Elements in Collection <%= key %></h1>
9
+ <table>
10
+ <% for row in mongo_get_value_as_array(key, start) %>
11
+ <tr>
12
+ <td>
13
+ <%= row.inspect %>
14
+ </td>
15
+ </tr>
16
+ <% end %>
17
+ </table>
18
+
19
+ <%= partial :next_more, :start => start, :size => size %>
20
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% if key = params[:key] %>
2
+ <h1>Key "<%= key %>" is a <%= resque.redis.type key %></h1>
3
+ <h2>size: <%= redis_get_size(key) %></h2>
4
+ <table>
5
+ <tr>
6
+ <td>
7
+ <%= redis_get_value_as_array(key) %>
8
+ </td>
9
+ </tr>
10
+ </table>
11
+ <% end %>
@@ -0,0 +1,42 @@
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
+ <abbr class="namespace" title="Mongo Connection">
20
+ <%= Resque.to_s %>
21
+ </abbr>
22
+ </div>
23
+
24
+ <% if @subtabs %>
25
+ <ul class='subnav'>
26
+ <% for subtab in @subtabs %>
27
+ <li <%= class_if_current "#{current_section}/#{subtab}" %>><a href="<%= current_section %>/<%= subtab %>"><span><%= subtab %></span></a></li>
28
+ <% end %>
29
+ </ul>
30
+ <% end %>
31
+
32
+ <div id="main">
33
+ <%= yield %>
34
+ </div>
35
+
36
+ <div id="footer">
37
+ <p>Powered by <a href="http://github.com/defunkt/resque">Resque</a> v<%=Resque::Version%></p>
38
+ <p>Connected to Mongo at <%= Resque.to_s %></p>
39
+ </div>
40
+
41
+ </body>
42
+ </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,65 @@
1
+ <% @subtabs = resque.queues unless partial? || params[:id].nil? %>
2
+
3
+ <% if queue = params[:id] %>
4
+ <h1>Jobs on <span class='hl'><%= queue %></span></h1>
5
+ <form method="POST" action="<%=u "/queues/#{queue}/remove" %>" class='remove-queue'>
6
+ <input type='submit' name='' value='Remove Queue' />
7
+ </form>
8
+ <% if !resque.queue_allows_delayed queue.to_sym %>
9
+ <p class='sub'>Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = resque.size(queue.to_sym)%></b> jobs</p><table class='jobs'>
10
+ <tr>
11
+ <th>Class</th>
12
+ <th>Args1</th>
13
+ </tr>
14
+ <% for job in (jobs = resque.peek(queue.to_sym, start, 20)) %>
15
+ <tr>
16
+ <td class='class'><%= job['class'] %></td>
17
+ <td class='args'><%=h job['args'].inspect %></td>
18
+ </tr>
19
+ <% end %>
20
+ <% else %>
21
+ <p class='sub'>Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = resque.size(queue.to_sym)%></b> jobs</p><table class='delays'>
22
+ <tr>
23
+ <th>Class</th>
24
+ <th>Args</th>
25
+ <th>Processes In</th>
26
+ </tr>
27
+ <% for job in (jobs = resque.peek(queue.to_sym, start, 20, :all_sorted)) %>
28
+ <tr>
29
+ <td class='class'><%= job['class'] %></td>
30
+ <td class='args'><%=h job['args'].inspect %></td>
31
+ <td class='delay'><%=h processes_in(job['delay_until']) %></td>
32
+ </tr>
33
+ <% end %>
34
+ <% end %>
35
+ <% if jobs.empty? %>
36
+ <tr>
37
+ <td class='no-data' colspan='2'>There are no pending jobs in this queue</td>
38
+ </tr>
39
+ <% end %>
40
+ </table>
41
+ <%= partial :next_more, :start => start, :size => size %>
42
+ <% else %>
43
+
44
+ <h1 class='wi'>Queues</h1>
45
+ <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>
46
+ <table class='queues'>
47
+ <tr>
48
+ <th>Name</th>
49
+ <th>Ready Jobs</th>
50
+ <th>Delayed Jobs</th>
51
+ </tr>
52
+ <% for queue in resque.queues.sort_by { |q| q.to_s } %>
53
+ <tr>
54
+ <td class='queue'><a class="queue" href="<%= url "queues/#{queue}" %>"><%= queue %></a></td>
55
+ <td class='size'><%= resque.ready_size queue.to_sym %></td>
56
+ <td class='size'><%= resque.delayed_size(queue.to_sym) if resque.queue_allows_delayed(queue.to_sym) %></td>
57
+ </tr>
58
+ <% end %>
59
+ <tr class="<%= Resque::Failure.count.zero? ? "failed" : "failure" %>">
60
+ <td class='queue failed'><a class="queue" href="<%= url :failed %>">failed</a></td>
61
+ <td class='size'><%= Resque::Failure.count %></td>
62
+ </tr>
63
+ </table>
64
+
65
+ <% end %>
@@ -0,0 +1,73 @@
1
+ <% @subtabs = %w( resque mongo keys ) %>
2
+
3
+ <% if params[:key] %>
4
+
5
+ <%= partial :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] == 'mongo' %>
24
+
25
+ <h1><%= resque.to_s %></h1>
26
+ <table class='stats'>
27
+ <% resque.mongo_stats.find.to_a.each do |hash| %>
28
+ <tr>
29
+ <th>
30
+ <%= hash['stat'] %>
31
+ </th>
32
+ <td>
33
+ <%= hash['value'].inspect %>
34
+ </td>
35
+ </tr>
36
+ <% end %>
37
+ </table>
38
+
39
+ <h1>Mongo Database Health</h1>
40
+ <table class='stats'>
41
+ <% resque.mongo.stats.each_pair do |key, value| %>
42
+ <tr>
43
+ <th>
44
+ <%= key %>
45
+ </th>
46
+ <td>
47
+ <%= value %>
48
+ </td>
49
+ </tr>
50
+ <% end %>
51
+ </table>
52
+
53
+ <% elsif params[:id] == 'keys' %>
54
+
55
+ <h1>Collections in <%= resque.to_s %></h1>
56
+ <table class='stats'>
57
+ <tr>
58
+ <th>collection</th>
59
+ <th>size</th>
60
+ </tr>
61
+ <% for key in resque.keys.sort %>
62
+ <tr>
63
+ <th>
64
+ <a href="<%=u "/stats/keys/#{key}" %>"><%= key %></a>
65
+ </th>
66
+ <td><%= resque.mongo[key].count %></td>
67
+ </tr>
68
+ <% end %>
69
+ </table>
70
+
71
+ <% else %>
72
+
73
+ <% end %>