Class: DelayedJobWeb
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- DelayedJobWeb
- Defined in:
- lib/delayed_job_web/application/app.rb
Instance Method Summary collapse
- #csrf_token ⇒ Object
- #csrf_token_tag ⇒ Object
- #current_page ⇒ Object
- #delayed_job ⇒ Object
- #delayed_jobs(type, queues = []) ⇒ Object
- #h(text) ⇒ Object
- #partial(template, local_vars = {}) ⇒ Object
- #path_prefix ⇒ Object
- #per_page ⇒ Object
- #poll ⇒ Object
- #show_for_polling(page) ⇒ Object
- #start ⇒ Object
- #tabs ⇒ Object
- #url_path(*path_parts) ⇒ Object (also: #u)
Instance Method Details
#csrf_token ⇒ Object
79 80 81 82 |
# File 'lib/delayed_job_web/application/app.rb', line 79 def csrf_token # Set up by Rack::Protection session[:csrf] end |
#csrf_token_tag ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/delayed_job_web/application/app.rb', line 84 def csrf_token_tag # If csrf_token is nil, and we submit a blank string authenticity_token # param, Rack::Protection will fail. if csrf_token "<input type='hidden' name='authenticity_token' value='#{h csrf_token}'>" end end |
#current_page ⇒ Object
32 33 34 |
# File 'lib/delayed_job_web/application/app.rb', line 32 def current_page url_path request.path_info.sub('/','') end |
#delayed_job ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/delayed_job_web/application/app.rb', line 71 def delayed_job begin Delayed::Job rescue false end end |
#delayed_jobs(type, queues = []) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/delayed_job_web/application/app.rb', line 142 def delayed_jobs(type, queues = []) rel = delayed_job rel = case type when :working rel.where('locked_at IS NOT NULL') when :failed rel.where('last_error IS NOT NULL') when :pending rel.where(:attempts => 0, :locked_at => nil) else rel end rel = rel.where(:queue => queues) unless queues.empty? rel end |
#h(text) ⇒ Object
52 53 54 |
# File 'lib/delayed_job_web/application/app.rb', line 52 def h(text) Rack::Utils.escape_html(text) end |
#partial(template, local_vars = {}) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/delayed_job_web/application/app.rb', line 166 def partial(template, local_vars = {}) @partial = true erb(template.to_sym, {:layout => false}, local_vars) ensure @partial = false end |
#path_prefix ⇒ Object
56 57 58 |
# File 'lib/delayed_job_web/application/app.rb', line 56 def path_prefix request.env['SCRIPT_NAME'] end |
#per_page ⇒ Object
40 41 42 |
# File 'lib/delayed_job_web/application/app.rb', line 40 def per_page 20 end |
#poll ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/delayed_job_web/application/app.rb', line 183 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 |
#show_for_polling(page) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/delayed_job_web/application/app.rb', line 192 def show_for_polling(page) content_type "text/html" @polling = true # show(page.to_sym, false).gsub(/\s{1,}/, ' ') @jobs = delayed_jobs(page.to_sym, @queues) erb(page.to_sym, {:layout => false}) end |
#start ⇒ Object
36 37 38 |
# File 'lib/delayed_job_web/application/app.rb', line 36 def start params[:start].to_i end |
#tabs ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/delayed_job_web/application/app.rb', line 60 def tabs [ {:name => 'Overview', :path => '/overview'}, {:name => 'Enqueued', :path => '/enqueued'}, {:name => 'Working', :path => '/working'}, {:name => 'Pending', :path => '/pending'}, {:name => 'Failed', :path => '/failed'}, {:name => 'Stats', :path => '/stats'} ] end |
#url_path(*path_parts) ⇒ Object Also known as: u
44 45 46 47 48 |
# File 'lib/delayed_job_web/application/app.rb', line 44 def url_path(*path_parts) url = [ path_prefix, path_parts ].join("/").squeeze('/') url += "?queues=#{@queues.join(",")}" unless @queues.empty? url end |