Permalink
Browse files

workers.erb => workers.mustache

  • Loading branch information...
1 parent 424a3ce commit ff6e1737ff9990dc18914c7ebb48affda7b6f5b7 @defunkt defunkt committed Mar 28, 2010
View
@@ -8,6 +8,7 @@
require 'resque/server/helpers'
require 'resque/server/views/layout'
+require 'resque/server/views/worker_list'
module Resque
class Server < Sinatra::Base
@@ -0,0 +1,99 @@
+{{#worker?}}
+ <h1>Worker {{to_s}}</h1>
+ <table class='workers'>
+ <tr>
+ <th>&nbsp;</th>
+ <th>Host</th>
+ <th>Pid</th>
+ <th>Started</th>
+ <th>Queues</th>
+ <th>Processed</th>
+ <th>Failed</th>
+ <th>Processing</th>
+ </tr>
+ <tr>
+ <td class='icon'>
+ {{{state_icon}}}
+
+ <% host, pid, queues = worker.to_s.split(':') %>
+ <td>{{worker_host}}</td>
+ <td>{{worker_pid}}</td>
+ <td><span class="time">{{started}}</span></td>
+ <td class='queues'>
+ {{linked_queues}}
+ </td>
+ <td>{{processed}}</td>
+ <td>{{failed}}></td>
+ <td class='process'>
+ {{#processing}}
+ {{#data}}
+ <code>{{#payload}}{{class}}{{/payload}}</code>
+ <small>
+ <a class="queue time" href="{{working_url}}">{{run_at}}</a>
+ </small>
+ {{/data}}
+ {{/processing}}
+
+ {{#not_processing}}
+ <span class='waiting'>Waiting for a job...</span>
+ {{/not_processing}}
+ </td>
+ </tr>
+ </table>
+{{/worker?}}
+
+{{#worker_not_found?}}
+ <h1>Worker doesn't exist</h1>
+{{/worker_not_found?}}
+
+{{#all_workers?}}
+ <h1 class='wi'>{{size}} Workers</h1>
+ <p class='intro'>
+ The workers listed below are all registered as active on your system.
+ </p>
+
+ <table class='workers'>
+ <tr>
+ <th>&nbsp;</th>
+ <th>Where</th>
+ <th>Queues</th>
+ <th>Processing</th>
+ </tr>
+ {{#workers}}
+ <tr class="{{state}}">
+ <td class='icon'>
+ {{{state_icon}}}
+ </td>
+
+ <td class='where'>
+ <a href="{{worker_url}}">{{worker_host}}:{{worker_pid}}</a></td>
+ <td class='queues'>
+ {{{linked_queues}}}
+ </td>
+
+ <td class='process'>
+ {{#processing}}
+ {{#queue}}
+ <code>{{#payload}}{{class}}{{/payload}}</code>
+ <small>
+ <a class="queue time" href="{{working_url}}">{{run_at}}</a>
+ </small>
+ {{/queue}}
+ {{/processing}}
+
+ {{#not_processing}}
+ <span class='waiting'>Waiting for a job...</span>
+ {{/not_processing}}
+ </td>
+ </tr>
+ {{/workers}}
+
+ {{#no_workers?}}
+ <tr>
+ <td colspan='4' class='no-data'>There are no registered workers</td>
+ </tr>
+ {{/no_workers?}}
+ </table>
+
+ <%=poll%>
+{{/all_workers?}}
@@ -0,0 +1,47 @@
+module Resque
+ module Views
+ class WorkerList < Layout
+ def state_icon
+ state = self[:state]
+ %(<img src="#{u(state)}.png" alt="#{state}" title="#{state}">)
+ end
+
+ # If we're not looking at a single worker, we're looking at all
+ # fo them.
+ def all_workers?
+ !params[:id]
+ end
+
+ # Host where the current worker lives.
+ def worker_host
+ worker_parts[0]
+ end
+
+ # PID of the current worker.
+ def worker_pid
+ worker_parts[1]
+ end
+
+ # Queues the current worker is concerned with.
+ def worker_queues
+ worker_parts[2..-1]
+ end
+
+ # The current worker's name split into three parts:
+ # [ host, pid, queues ]
+ def worker_parts
+ self[:to_s].split(':')
+ end
+
+ # Worker URL of the current worker
+ def worker_url
+ u "/workers/#{self[:to_s]}"
+ end
+
+ # Working URL of the current working
+ def working_url
+ u "/working/#{self[:to_s]}"
+ end
+ end
+ end
+end
@@ -1,78 +0,0 @@
-<% if params[:id] && worker = Resque::Worker.find(params[:id]) %>
-
- <h1>Worker <%= worker %></h1>
- <table class='workers'>
- <tr>
- <th>&nbsp;</th>
- <th>Host</th>
- <th>Pid</th>
- <th>Started</th>
- <th>Queues</th>
- <th>Processed</th>
- <th>Failed</th>
- <th>Processing</th>
- </tr>
- <tr>
- <td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
-
- <% host, pid, queues = worker.to_s.split(':') %>
- <td><%= host %></td>
- <td><%= pid %></td>
- <td><span class="time"><%= worker.started %></span></td>
- <td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
- <td><%= worker.processed %></td>
- <td><%= worker.failed %></td>
- <td class='process'>
- <% data = worker.processing || {} %>
- <% if data['queue'] %>
- <code><%= data['payload']['class'] %></code>
- <small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
- <% else %>
- <span class='waiting'>Waiting for a job...</span>
- <% end %>
- </td>
- </tr>
- </table>
-
-<% elsif params[:id] %>
-
-<h1>Worker doesn't exist</h1>
-
-<% else %>
-
- <h1 class='wi'><%= resque.workers.size %> Workers</h1>
- <p class='intro'>The workers listed below are all registered as active on your system.</p>
- <table class='workers'>
- <tr>
- <th>&nbsp;</th>
- <th>Where</th>
- <th>Queues</th>
- <th>Processing</th>
- </tr>
- <% for worker in (workers = resque.workers.sort_by { |w| w.to_s }) %>
- <tr class="<%=state = worker.state%>">
- <td class='icon'><img src="<%=u state %>.png" alt="<%= state %>" title="<%= state %>"></td>
-
- <% host, pid, queues = worker.to_s.split(':') %>
- <td class='where'><a href="<%=u "workers/#{worker}"%>"><%= host %>:<%= pid %></a></td>
- <td class='queues'><%= queues.split(',').map { |q| '<a class="queue-tag" href="' + u("/queues/#{q}") + '">' + q + '</a>'}.join('') %></td>
-
- <td class='process'>
- <% data = worker.processing || {} %>
- <% if data['queue'] %>
- <code><%= data['payload']['class'] %></code>
- <small><a class="queue time" href="<%=u "/working/#{worker}" %>"><%= data['run_at'] %></a></small>
- <% else %>
- <span class='waiting'>Waiting for a job...</span>
- <% end %>
- </td>
- </tr>
- <% end %>
- <% if workers.empty? %>
- <tr>
- <td colspan='4' class='no-data'>There are no registered workers</td>
- </tr>
- <% end %>
- </table>
- <%=poll%>
-<% end %>
@@ -0,0 +1,35 @@
+module Resque
+ module Views
+ class Workers < WorkerList
+ def worker?
+ if id = params[:id]
+ Resque::Worker.find(id)
+ end
+ end
+
+ def worker_not_found?
+ params[:id] && !Resque::Worker.find(id)
+ end
+
+ def workers
+ Resque.workers.sort_by { |w| w.to_s }
+ end
+
+ def linked_queues
+ links = self[:queues].map do |q|
+ %(<a class="queue-tag" href="#{u("/queues/#{q}")}">#{q}</a>)
+ end
+
+ links.join('')
+ end
+
+ def no_workers?
+ workers.empty?
+ end
+
+ def not_processing
+ !self[:processing]
+ end
+ end
+ end
+end
@@ -1,6 +1,6 @@
module Resque
module Views
- class Working < Layout
+ class Working < WorkerList
# If we're only looking at a single worker, return it as the
# context.
def single_worker?
@@ -10,12 +10,6 @@ def single_worker?
end
end
- # If we're not looking at a single worker, we're looking at all
- # fo them.
- def all_workers?
- !params[:id]
- end
-
# A sorted array of workers currently working.
def working
Resque.working.
@@ -43,32 +37,6 @@ def workers_total
Resque.workers.size
end
- # A full URL to the icon representing a worker's state.
- def state_icon
- u(self[:state]) + '.png'
- end
-
- # Host where the current worker lives.
- def worker_host
- worker_parts[0]
- end
-
- # PID of the current worker.
- def worker_pid
- worker_parts[1]
- end
-
- # Queues the current worker is concerned with.
- def worker_queues
- worker_parts[2..-1]
- end
-
- # The current worker's name split into three parts:
- # [ host, pid, queues ]
- def worker_parts
- self[:to_s].split(':')
- end
-
# TODO: Mustache method_missing this guy
def queue
self[:queue]
@@ -78,16 +46,6 @@ def queue
def queue_url
u "/queues/#{queue}"
end
-
- # Worker URL of the current worker
- def worker_url
- u "/workers/#{self[:to_s]}"
- end
-
- # Working URL of the current working
- def working_url
- u "/working/#{self[:to_s]}"
- end
end
end
end

0 comments on commit ff6e173

Please sign in to comment.