class Resque::Server

Public Class Methods

tabs() click to toggle source
# File lib/resque/server.rb, line 266
def self.tabs
  @tabs ||= ["Overview", "Working", "Failed", "Queues", "Workers", "Stats"]
end

Public Instance Methods

class_if_current(path = '') click to toggle source
# File lib/resque/server.rb, line 48
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 35
def current_page
  url_path request.path_info.sub('/','')
end
current_section() click to toggle source
# File lib/resque/server.rb, line 31
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 117
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 113
def partial?
  @partial
end
path_prefix() click to toggle source
# File lib/resque/server.rb, line 44
def path_prefix
  request.env['SCRIPT_NAME']
end
poll() click to toggle source
# File lib/resque/server.rb, line 124
def poll
  if @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 62
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 77
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 262
def resque
  Resque
end
show(page, layout = true) click to toggle source
# File lib/resque/server.rb, line 135
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 92
def show_args(args)
  Array(args).map do |a|
    a.to_yaml
  end.join("\n")
end
show_for_polling(page) click to toggle source
# File lib/resque/server.rb, line 144
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 52
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 58
def tabs
  Resque::Server.tabs
end
url_path(*path_parts) click to toggle source
# File lib/resque/server.rb, line 39
def url_path(*path_parts)
  [ path_prefix, path_parts ].join("/").squeeze('/')
end
worker_hosts() click to toggle source
# File lib/resque/server.rb, line 98
def worker_hosts
  @worker_hosts ||= worker_hosts!
end
worker_hosts!() click to toggle source
# File lib/resque/server.rb, line 102
def worker_hosts!
  hosts = Hash.new { [] }

  Resque.workers.each do |worker|
    host, _ = worker.to_s.split(':')
    hosts[host] += [worker.to_s]
  end

  hosts
end