Class: DelayedJobMongoidWeb

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/delayed_job_mongoid_web/application/app.rb

Instance Method Summary collapse

Instance Method Details

#current_pageObject



14
15
16
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 14

def current_page
  url_path request.path_info.sub('/','')
end

#delayed_jobObject



46
47
48
49
50
51
52
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 46

def delayed_job
  begin
    Delayed::Job
  rescue
    false
  end
end

#delayed_job_filter(crit, type) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 100

def delayed_job_filter(crit, type)
  case type
  when :enqueued
    crit.where({})
  when :working
    crit.where({:locked_at.ne =>nil }) #'locked_at is not null'
  when :failed
    crit.where({:last_error.ne => nil }) # 'last_error is not null'
  when :pending
    crit.where({attempts: 0})
  end
end

#delayed_jobs(type) ⇒ Object



96
97
98
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 96

def delayed_jobs(type)
  delayed_job_filter(delayed_job,type)
end

#partial(template, local_vars = {}) ⇒ Object



117
118
119
120
121
122
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 117

def partial(template, local_vars = {})
  @partial = true
  haml(template.to_sym, {:layout => false}, local_vars)
ensure
  @partial = false
end

#path_prefixObject



31
32
33
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 31

def path_prefix
  request.env['SCRIPT_NAME']
end

#per_pageObject



22
23
24
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 22

def per_page
  20
end

#pollObject



134
135
136
137
138
139
140
141
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 134

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



143
144
145
146
147
148
149
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 143

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)
  haml(page.to_sym, {:layout => false})
end

#startObject



18
19
20
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 18

def start
  params[:start].to_i
end

#tabsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 35

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



26
27
28
# File 'lib/delayed_job_mongoid_web/application/app.rb', line 26

def url_path(*path_parts)
  [ path_prefix, path_parts ].join("/").squeeze('/')
end