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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 115 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
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 196 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
256 257 258 259 260 261 262 263 264 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 256 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
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 233 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
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 217 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
266 267 268 269 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 266 def cleaner_stale @cleaner.clear_stale redirect_to cleaner_resque_path end |
#clear_statuses ⇒ Object
175 176 177 178 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 175 def clear_statuses Resque::Plugins::Status::Hash.clear redirect_to statuses_resque_path end |
#continue_worker ⇒ Object
64 65 66 67 68 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 64 def continue_worker worker = find_worker(params[:worker]) worker.continue if worker redirect_to workers_resque_path end |
#kill ⇒ Object
188 189 190 191 192 193 194 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 188 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
58 59 60 61 62 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 58 def pause_worker worker = find_worker(params[:worker]) worker.pause if worker redirect_to workers_resque_path end |
#poll ⇒ Object
26 27 28 29 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 26 def poll @polling = true render(:text => (render_to_string(:action => "#{params[:page]}", :formats => [:html], :layout => false, :resque => Resque)).gsub(/\s{1,}/, ' ')) end |
#queues ⇒ Object
22 23 24 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 22 def queues render('_queues', :locals => {:partial => nil}) end |
#remove_from_schedule ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 141 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
42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 42 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
70 71 72 73 74 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 70 def restart_worker worker = find_worker(params[:worker]) worker.restart if worker redirect_to workers_resque_path end |
#schedule ⇒ Object
resque-scheduler actions
105 106 107 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 105 def schedule @farm_status = ResqueScheduler.farm_status end |
#schedule_requeue ⇒ Object
109 110 111 112 113 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 109 def schedule_requeue config = Resque.schedule[params['job_name']] Resque::Scheduler.enqueue_from_config(config) redirect_to overview_resque_path end |
#start_scheduler ⇒ Object
152 153 154 155 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 152 def start_scheduler ResqueScheduler.start(params[:ip]) redirect_to schedule_resque_path end |
#start_worker ⇒ Object
76 77 78 79 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 76 def start_worker Resque::Worker.start(params) redirect_to workers_resque_path end |
#stats ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 81 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
180 181 182 183 184 185 186 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 180 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
31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 31 def status_poll @polling = true @start = params[:start].to_i @end = @start + (params[:per_page] || 20) @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end) rescue [] @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
164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 164 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
157 158 159 160 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 157 def stop_scheduler ResqueScheduler.quit(params[:ip]) redirect_to schedule_resque_path end |
#stop_worker ⇒ Object
52 53 54 55 56 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 52 def stop_worker worker = find_worker(params[:worker]) worker.quit if worker redirect_to workers_resque_path end |
#working ⇒ Object
18 19 20 |
# File 'app/controllers/resque_manager/resque_controller.rb', line 18 def working render('_working') end |