class DelayedJobWeb

Public Instance Methods

csrf_token() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 95
def csrf_token
  # Set up by Rack::Protection
  session[:csrf]
end
csrf_token_tag() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 100
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() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 34
def current_page
  url_path request.path_info.sub('/','')
end
delayed_job() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 87
def delayed_job
  begin
    Delayed::Job
  rescue
    false
  end
end
delayed_jobs(type, queues = []) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 164
def delayed_jobs(type, queues = [])
  rel = delayed_job

  rel =
    case type
    when :working
      rel.where('locked_at IS NOT NULL AND failed_at IS 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) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 68
def h(text)
  Rack::Utils.escape_html(text)
end
partial(template, local_vars = {}) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 188
def partial(template, local_vars = {})
  @partial = true
  erb(template.to_sym, {:layout => false}, local_vars)
ensure
  @partial = false
end
path_prefix() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 72
def path_prefix
  request.env['SCRIPT_NAME']
end
per_page() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 42
def per_page
  params[:per_page].to_i > 0 ? params[:per_page].to_i : 20
end
poll() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 205
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
queue_path(queue) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 54
def queue_path(queue)
  with_queue(queue) do
    url_path(:overview)
  end
end
show_for_polling(page) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 214
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() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 38
def start
  params[:start].to_i
end
tabs() click to toggle source
# File lib/delayed_job_web/application/app.rb, line 76
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
u(*path_parts)
Alias for: url_path
url_path(*path_parts) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 46
def url_path(*path_parts)
  url = [ path_prefix, path_parts ].join("/").squeeze('/')
  url += "?queues=#{CGI.escape(@queues.join(","))}" unless @queues.empty?
  url
end
Also aliased as: u
with_queue(queue, &block) click to toggle source
# File lib/delayed_job_web/application/app.rb, line 60
def with_queue(queue, &block)
  aux_queues = @queues
  @queues = Array(queue)
  result  = block.call
  @queues = aux_queues
  result
end