Class: ResqueManager::ResqueController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ResqueManager::ResqueController
- Defined in:
- app/controllers/resque_manager/resque_controller.rb
Instance Method Summary collapse
- #add_scheduled_job ⇒ Object
- #cleaner ⇒ Object
- #cleaner_dump ⇒ Object
- #cleaner_exec ⇒ Object
- #cleaner_list ⇒ Object
- #cleaner_stale ⇒ Object
- #clear_statuses ⇒ Object
- #continue_worker ⇒ Object
- #kill ⇒ Object
- #pause_worker ⇒ Object
- #poll ⇒ Object
- #queues ⇒ Object
- #remove_from_schedule ⇒ Object
- #remove_job ⇒ Object
- #restart_worker ⇒ Object
-
#schedule ⇒ Object
resque-scheduler actions.
- #schedule_requeue ⇒ Object
- #start_scheduler ⇒ Object
- #start_worker ⇒ Object
- #stats ⇒ Object
- #status ⇒ Object
- #status_poll ⇒ Object
-
#statuses ⇒ Object
resque-status actions.
- #stop_scheduler ⇒ Object
- #stop_worker ⇒ Object
- #working ⇒ Object
Instance Method Details
#add_scheduled_job ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 113 def add_scheduled_job errors = [] if Resque.schedule.keys.include?(params[:name]) errors << 'Name already exists' end if params[:ip].blank? errors << 'You must enter an ip address for the server you want this job to run on.' end if params[:cron].blank? errors << 'You must enter the cron schedule.' end if errors.blank? config = {params['name'] => {'class' => params['class'], 'ip' => params['ip'], 'cron' => params['cron'], 'args' => Resque.decode(params['args'].blank? ? nil : params['args']), 'description' => params['description']} } Resque.redis.rpush(:scheduled, Resque.encode(config)) ResqueScheduler.restart('ip') else flash[:error] = errors.join('<br>') end redirect_to(:action => 'schedule') end |
#cleaner ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 193 def cleaner load_cleaner_filter @jobs = @cleaner.select @stats, @total = {}, {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0} @jobs.each do |job| klass = job["payload"]["class"] failed_at = Time.parse job["failed_at"] @stats[klass] ||= {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0} items = [@stats[klass], @total] items.each { |a| a["total"] += 1 } items.each { |a| a["1h"] += 1 } if failed_at >= hours_ago(1) items.each { |a| a["3h"] += 1 } if failed_at >= hours_ago(3) items.each { |a| a["1d"] += 1 } if failed_at >= hours_ago(24) items.each { |a| a["3d"] += 1 } if failed_at >= hours_ago(24*3) items.each { |a| a["7d"] += 1 } if failed_at >= hours_ago(24*7) end end |
#cleaner_dump ⇒ Object
253 254 255 256 257 258 259 260 261 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 253 def cleaner_dump load_cleaner_filter block = filter_block failures = @cleaner.select(&block) # pretty generate throws an error with the json gem on jruby output = JSON.pretty_generate(failures) rescue failures.to_json render :json => output end |
#cleaner_exec ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 230 def cleaner_exec load_cleaner_filter if params[:select_all_pages]!="1" @sha1 = {} params[:sha1].split(",").each { |s| @sha1[s] = true } end block = filter_block @count = case params[:form_action] when "clear" then @cleaner.clear(&block) when "retry_and_clear" then @cleaner.requeue(true, &block) when "retry" then @cleaner.requeue(false, {}, &block) end @link_url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}" end |
#cleaner_list ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 214 def cleaner_list load_cleaner_filter block = filter_block @failed = @cleaner.select(&block).reverse url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}" @dump_url = "cleaner_dump?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}" @paginate = ResqueManager::Paginate.new(@failed, url, params[:p].to_i) @klasses = @cleaner.stats_by_class.keys @exceptions = @cleaner.stats_by_exception.keys @count = @cleaner.select(&block).size end |
#cleaner_stale ⇒ Object
263 264 265 266 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 263 def cleaner_stale @cleaner.clear_stale redirect_to :action => "cleaner" end |
#clear_statuses ⇒ Object
173 174 175 176 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 173 def clear_statuses Resque::Plugins::Status::Hash.clear redirect_to(:action => 'statuses') end |
#continue_worker ⇒ Object
61 62 63 64 65 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 61 def continue_worker worker = find_worker(params[:worker]) worker.continue if worker redirect_to(:action => "workers") end |
#kill ⇒ Object
185 186 187 188 189 190 191 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 185 def kill Resque::Plugins::Status::Hash.kill(params[:id]) s = Resque::Plugins::Status::Hash.get(params[:id]) s.status = 'killed' Resque::Plugins::Status::Hash.set(params[:id], s) redirect_to(:action => 'statuses') end |
#pause_worker ⇒ Object
55 56 57 58 59 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 55 def pause_worker worker = find_worker(params[:worker]) worker.pause if worker redirect_to(:action => "workers") end |
#poll ⇒ Object
23 24 25 26 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 23 def poll @polling = true render(:text => (render_to_string(:action => "#{params[:page]}", :formats => [:html], :layout => false, :resque => Resque)).gsub(/\s{1,}/, ' ')) end |
#queues ⇒ Object
19 20 21 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 19 def queues render('_queues', :locals => {:partial => nil}) end |
#remove_from_schedule ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 139 def remove_from_schedule Resque.list_range(:scheduled, 0, -0).each do |s| if s[params['job_name']] Resque.redis.lrem(:scheduled, 0, s.to_json) # Restart the scheduler on the server that has changed it's schedule ResqueScheduler.restart(params['ip']) end end redirect_to(:action => 'schedule') end |
#remove_job ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 39 def remove_job # We can only dequeue a job when that job is in the same application as the UI. # Otherwise we get an error when we try to constantize a class that does not exist # in the application the UI is in. if ResqueManager.applications.blank? Resque.dequeue(params['class'].constantize, *Resque.decode(params['args'])) redirect_to request.referrer end end |
#restart_worker ⇒ Object
67 68 69 70 71 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 67 def restart_worker worker = find_worker(params[:worker]) worker.restart if worker redirect_to(:action => "workers") end |
#schedule ⇒ Object
resque-scheduler actions
103 104 105 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 103 def schedule @farm_status = ResqueScheduler.farm_status end |
#schedule_requeue ⇒ Object
107 108 109 110 111 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 107 def schedule_requeue config = Resque.schedule[params['job_name']] Resque::Scheduler.enqueue_from_config(config) redirect_to(:action => 'overview') end |
#start_scheduler ⇒ Object
151 152 153 154 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 151 def start_scheduler ResqueScheduler.start(params[:ip]) redirect_to(:action => 'schedule') end |
#start_worker ⇒ Object
73 74 75 76 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 73 def start_worker Resque::Worker.start(params) redirect_to(:action => "workers") end |
#stats ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 78 def stats unless params[:id] redirect_to(:action => 'stats', :id => 'resque') end if params[:id] == 'txt' info = Resque.info stats = [] stats << "resque.pending=#{info[:pending]}" stats << "resque.processed+=#{info[:processed]}" stats << "resque.failed+=#{info[:failed]}" stats << "resque.workers=#{info[:workers]}" stats << "resque.working=#{info[:working]}" Resque.queues.each do |queue| stats << "queues.#{queue}=#{Resque.size(queue)}" end render(:text => stats.join("</br>").html_safe) end end |
#status ⇒ Object
178 179 180 181 182 183 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 178 def status @status = Resque::Plugins::Status::Hash.get(params[:id]) if params[:format] == 'js' render :text => @status.to_json end end |
#status_poll ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 28 def status_poll @polling = true @start = params[:start].to_i @end = @start + (params[:per_page] || 20) @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end) @size = Resque::Plugins::Status::Hash.status_ids.size render(:text => (render_to_string(:action => 'statuses', :formats => [:html], :layout => false))) end |
#statuses ⇒ Object
resque-status actions
163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 163 def statuses @start = params[:start].to_i @end = @start + (params[:per_page] || 20) @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end) @size = Resque::Plugins::Status::Hash.status_ids.size if params[:format] == 'js' render :text => @statuses.to_json end end |
#stop_scheduler ⇒ Object
156 157 158 159 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 156 def stop_scheduler ResqueScheduler.quit(params[:ip]) redirect_to(:action => 'schedule') end |
#stop_worker ⇒ Object
49 50 51 52 53 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 49 def stop_worker worker = find_worker(params[:worker]) worker.quit if worker redirect_to(:action => "workers") end |
#working ⇒ Object
15 16 17 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 15 def working render('_working') end |