Module: ResqueManager::ResqueHelper

Defined in:
app/helpers/resque_manager/resque_helper.rb

Instance Method Summary collapse

Instance Method Details

#class_filter(id, name, klasses, value) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'app/helpers/resque_manager/resque_helper.rb', line 120

def class_filter(id, name, klasses, value)
  html = "<select id=\"#{id}\" name=\"#{name}\">"
  html += "<option value=\"\">-</option>"
  klasses.each do |k|
    selected = k == value ? 'selected="selected"' : ''
    html += "<option #{selected} value=\"#{k}\">#{k}</option>"
  end
  html += "</select>"
  html.html_safe
end

#class_if_current(page = '') ⇒ Object



32
33
34
# File 'app/helpers/resque_manager/resque_helper.rb', line 32

def class_if_current(page = '')
  'class="current"' if current_page.include? page.to_s
end

#current_pageObject



18
19
20
# File 'app/helpers/resque_manager/resque_helper.rb', line 18

def current_page
  url request.path_info.sub('/', '').downcase
end

#current_sectionObject



14
15
16
# File 'app/helpers/resque_manager/resque_helper.rb', line 14

def current_section
  (request.path_info.sub('/', '').split('/').first || 'overview').downcase
end

#exception_filter(id, name, exceptions, value) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'app/helpers/resque_manager/resque_helper.rb', line 131

def exception_filter(id, name, exceptions, value)
  html = "<select id=\"#{id}\" name=\"#{name}\">"
  html += "<option value=\"\">-</option>"
  exceptions.each do |ex|
    selected = ex == value ? 'selected="selected"' : ''
    html += "<option #{selected} value=\"#{ex}\">#{ex}</option>"
  end
  html += "</select>"
  html.html_safe
end

#find_worker(worker) ⇒ Object



41
42
43
44
45
# File 'app/helpers/resque_manager/resque_helper.rb', line 41

def find_worker(worker)
  first_part, *rest = worker.split(':')
  first_part.gsub!(/_/, '.')
  Resque::Worker.find("#{first_part}:#{rest.join(':')}")
end

#flash_helperObject



4
5
6
7
8
# File 'app/helpers/resque_manager/resque_helper.rb', line 4

def flash_helper
  [:notice, :warning, :message, :error].collect do |key|
    (:div, flash[key], :class => "flash #{key}") unless flash[key].blank?
  end.join
end

#format_time(t) ⇒ Object



10
11
12
# File 'app/helpers/resque_manager/resque_helper.rb', line 10

def format_time(t)
  t.strftime("%Y/%m/%d %H:%M:%S %Z")
end

#partial?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/helpers/resque_manager/resque_helper.rb', line 77

def partial?
  @partial
end

#path_prefixObject



28
29
30
# File 'app/helpers/resque_manager/resque_helper.rb', line 28

def path_prefix
  request.env['SCRIPT_NAME']
end

#pollObject



81
82
83
84
85
86
87
88
# File 'app/helpers/resque_manager/resque_helper.rb', line 81

def poll
  if @polling
    text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}"
  else
    text = link_to('Live Poll', poll_resque_path(page: current_section), :rel => 'poll')
  end
  "<p class='poll'>#{text}</p>".html_safe
end

#redis_get_size(key) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/resque_manager/resque_helper.rb', line 47

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
  end
end

#redis_get_value_as_array(key) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/resque_manager/resque_helper.rb', line 60

def redis_get_value_as_array(key)
  case Resque.redis.type(key)
    when 'none'
      []
    when 'list'
      Resque.list_range(key, 0, 20)
    when 'set'
      Resque.redis.smembers(key)
    when 'string'
      [Resque.redis.get(key)]
  end
end

#resqueObject



99
100
101
# File 'app/helpers/resque_manager/resque_helper.rb', line 99

def resque
  Resque
end

#show_args(args) ⇒ Object



73
74
75
# File 'app/helpers/resque_manager/resque_helper.rb', line 73

def show_args(args)
  Array(args).map { |a| a.inspect }.join("\n")
end

#status_poll(start) ⇒ Object



90
91
92
93
94
95
96
97
# File 'app/helpers/resque_manager/resque_helper.rb', line 90

def status_poll(start)
  if @polling
    text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}"
  else
    text = link_to('Live Poll', status_poll_resque_path({:start => start}), :rel => 'poll')
  end
  "<p class='poll'>#{text}</p>".html_safe
end

#tab(name) ⇒ Object



36
37
38
39
# File 'app/helpers/resque_manager/resque_helper.rb', line 36

def tab(name)
  dname = "#{name.to_s.downcase}"
  "<li #{class_if_current(dname)}>#{link_to(name, url(dname))}</li>".html_safe
end

#time_filter(id, name, value) ⇒ Object

resque-cleaner helpers



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/resque_manager/resque_helper.rb', line 105

def time_filter(id, name, value)
  html = "<select id=\"#{id}\" name=\"#{name}\">"
  html += "<option value=\"\">-</option>"
  [1, 3, 6, 12, 24].each do |h|
    selected = h.to_s == value ? 'selected="selected"' : ''
    html += "<option #{selected} value=\"#{h}\">#{h} #{h==1 ? "hour" : "hours"} ago</option>"
  end
  [3, 7, 14, 28].each do |d|
    selected = (d*24).to_s == value ? 'selected="selected"' : ''
    html += "<option #{selected} value=\"#{d*24}\">#{d} days ago</option>"
  end
  html += "</select>"
  html.html_safe
end

#url(*path_parts) ⇒ Object Also known as: u



22
23
24
# File 'app/helpers/resque_manager/resque_helper.rb', line 22

def url(*path_parts)
  [path_prefix, path_parts].join("/").squeeze('/')
end