class Resque::Server
Public Class Methods
tabs()
click to toggle source
# File lib/resque/server.rb, line 285 def self.tabs @tabs ||= ["Overview", "Working", "Failed", "Queues", "Workers", "Stats"] end
url_prefix()
click to toggle source
# File lib/resque/server.rb, line 293 def self.url_prefix (@url_prefix.nil? || @url_prefix.empty?) ? '' : @url_prefix + '/' end
url_prefix=(url_prefix)
click to toggle source
# File lib/resque/server.rb, line 289 def self.url_prefix=(url_prefix) @url_prefix = url_prefix end
Public Instance Methods
class_if_current(path = '')
click to toggle source
# File lib/resque/server.rb, line 49 def class_if_current(path = '') 'class="current"' if current_page[0, path.size] == path end
current_page()
click to toggle source
# File lib/resque/server.rb, line 36 def current_page url_path request.path_info.sub('/','') end
current_section()
click to toggle source
# File lib/resque/server.rb, line 32 def current_section url_path request.path_info.sub('/','').split('/')[0].downcase end
partial(template, local_vars = {})
click to toggle source
# File lib/resque/server.rb, line 124 def partial(template, local_vars = {}) @partial = true erb(template.to_sym, {:layout => false}, local_vars) ensure @partial = false end
partial?()
click to toggle source
# File lib/resque/server.rb, line 120 def partial? @partial end
path_prefix()
click to toggle source
# File lib/resque/server.rb, line 45 def path_prefix request.env['SCRIPT_NAME'] end
poll()
click to toggle source
# File lib/resque/server.rb, line 131 def poll if defined?(@polling) && @polling text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}" else text = "<a href='#{u(request.path_info)}.poll' rel='poll'>Live Poll</a>" end "<p class='poll'>#{text}</p>" end
redis_get_size(key)
click to toggle source
# File lib/resque/server.rb, line 67 def redis_get_size(key) case Resque.redis.type(key) when 'none' [] when 'list' Resque.redis.llen(key) when 'set' Resque.redis.scard(key) when 'string' Resque.redis.get(key).length when 'zset' Resque.redis.zcard(key) end end
redis_get_value_as_array(key, start=0)
click to toggle source
# File lib/resque/server.rb, line 82 def redis_get_value_as_array(key, start=0) case Resque.redis.type(key) when 'none' [] when 'list' Resque.redis.lrange(key, start, start + 20) when 'set' Resque.redis.smembers(key)[start..(start + 20)] when 'string' [Resque.redis.get(key)] when 'zset' Resque.redis.zrange(key, start, start + 20) end end
resque()
click to toggle source
# File lib/resque/server.rb, line 281 def resque Resque end
show(page, layout = true)
click to toggle source
# File lib/resque/server.rb, line 142 def show(page, layout = true) response["Cache-Control"] = "max-age=0, private, must-revalidate" begin erb page.to_sym, {:layout => layout}, :resque => Resque rescue Errno::ECONNREFUSED erb :error, {:layout => false}, :error => "Can't connect to Redis! (#{Resque.redis_id})" end end
show_args(args)
click to toggle source
# File lib/resque/server.rb, line 97 def show_args(args) Array(args).map do |a| a.to_yaml end.join("\n") rescue args.to_s end
show_for_polling(page)
click to toggle source
# File lib/resque/server.rb, line 151 def show_for_polling(page) content_type "text/html" @polling = true show(page.to_sym, false).gsub(/\s{1,}/, ' ') end
tab(name)
click to toggle source
# File lib/resque/server.rb, line 53 def tab(name) dname = name.to_s.downcase path = url_path(dname) "<li #{class_if_current(path)}><a href='#{path}'>#{name}</a></li>" end
tabs()
click to toggle source
# File lib/resque/server.rb, line 59 def tabs Resque::Server.tabs end
url_path(*path_parts)
click to toggle source
# File lib/resque/server.rb, line 40 def url_path(*path_parts) [ url_prefix, path_prefix, path_parts ].join("/").squeeze('/') end
url_prefix()
click to toggle source
# File lib/resque/server.rb, line 63 def url_prefix Resque::Server.url_prefix end
worker_hosts()
click to toggle source
# File lib/resque/server.rb, line 105 def worker_hosts @worker_hosts ||= worker_hosts! end
worker_hosts!()
click to toggle source
# File lib/resque/server.rb, line 109 def worker_hosts! hosts = Hash.new { [] } Resque.workers.each do |worker| host, _ = worker.to_s.split(':') hosts[host] += [worker.to_s] end hosts end