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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 114 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(params['ip']) else flash[:error] = errors.join('<br>').html_safe end redirect_to schedule_resque_path end |
#cleaner ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 195 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
255 256 257 258 259 260 261 262 263 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 255 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
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 232 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
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 216 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
265 266 267 268 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 265 def cleaner_stale @cleaner.clear_stale redirect_to cleaner_resque_path end |
#clear_statuses ⇒ Object
174 175 176 177 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 174 def clear_statuses Resque::Plugins::Status::Hash.clear redirect_to statuses_resque_path end |
#continue_worker ⇒ Object
63 64 65 66 67 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 63 def continue_worker worker = find_worker(params[:worker]) worker.continue if worker redirect_to workers_resque_path end |
#kill ⇒ Object
187 188 189 190 191 192 193 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 187 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 statuses_resque_path end |
#pause_worker ⇒ Object
57 58 59 60 61 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 57 def pause_worker worker = find_worker(params[:worker]) worker.pause if worker redirect_to workers_resque_path end |
#poll ⇒ Object
25 26 27 28 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 25 def poll @polling = true render(:text => (render_to_string(:action => "#{params[:page]}", :formats => [:html], :layout => false, :resque => Resque)).gsub(/\s{1,}/, ' ')) end |
#queues ⇒ Object
21 22 23 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 21 def queues render('_queues', :locals => {:partial => nil}) end |
#remove_from_schedule ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 140 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 schedule_resque_path end |
#remove_job ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 41 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'])) end redirect_to request.referrer end |
#restart_worker ⇒ Object
69 70 71 72 73 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 69 def restart_worker worker = find_worker(params[:worker]) worker.restart if worker redirect_to workers_resque_path end |
#schedule ⇒ Object
resque-scheduler actions
104 105 106 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 104 def schedule @farm_status = ResqueScheduler.farm_status end |
#schedule_requeue ⇒ Object
108 109 110 111 112 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 108 def schedule_requeue config = Resque.schedule[params['job_name']] Resque::Scheduler.enqueue_from_config(config) redirect_to overview_resque_path 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 schedule_resque_path end |
#start_worker ⇒ Object
75 76 77 78 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 75 def start_worker Resque::Worker.start(params) redirect_to workers_resque_path end |
#stats ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 80 def stats unless params[:id] redirect_to(stats_resque_path(: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
179 180 181 182 183 184 185 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 179 def status @status = Resque::Plugins::Status::Hash.get(params[:id]) respond_to do |format| format.js { render json: @status } format.html { render :status } end end |
#status_poll ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 30 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 172 |
# 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 respond_to do |format| format.js { render json: @statuses } format.html { render :statuses } 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 schedule_resque_path end |
#stop_worker ⇒ Object
51 52 53 54 55 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 51 def stop_worker worker = find_worker(params[:worker]) worker.quit if worker redirect_to workers_resque_path end |
#working ⇒ Object
17 18 19 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 17 def working render('_working') end |