Class: Supervisor::App

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

Instance Method Summary collapse

Instance Method Details

#current_pageObject

SINTRA APP ################################



39
40
41
# File 'lib/supervisor/application/app.rb', line 39

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

#delayed_jobObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/supervisor/application/app.rb', line 26

def delayed_job
  begin
    if (Supervisor.methods - Object.methods).count > 1
      Supervisor::Job
    else
      Delayed::Job
    end
  rescue
    nil
  end
end

#delayed_job_sql(type) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/supervisor/application/app.rb', line 64

def delayed_job_sql(type)
  case type
  when :enqueued
    ''
  when :working
    'locked_at is not null'
  when :failed
    'last_error is not null'
  when :pending
    'attempts = 0'
  end
end

#delayed_jobs(type) ⇒ Object



60
61
62
# File 'lib/supervisor/application/app.rb', line 60

def delayed_jobs(type)
  delayed_job.where(delayed_job_sql(type))
end

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



77
78
79
80
81
82
# File 'lib/supervisor/application/app.rb', line 77

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

#path_prefixObject



56
57
58
# File 'lib/supervisor/application/app.rb', line 56

def path_prefix
  request.env['SCRIPT_NAME']
end

#per_pageObject



47
48
49
# File 'lib/supervisor/application/app.rb', line 47

def per_page
  25
end

#pollObject



84
85
86
87
88
89
90
91
# File 'lib/supervisor/application/app.rb', line 84

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



93
94
95
96
97
98
99
# File 'lib/supervisor/application/app.rb', line 93

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



43
44
45
# File 'lib/supervisor/application/app.rb', line 43

def start
  params[:start].to_i
end

#tabsObject

SINATRA ROUTES/ACTIONS ##########################



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

def tabs
  [
    {:name => 'Overview', :path => '/overview'},
    {:name => 'Enqueued', :path => '/enqueued'},
    {:name => 'Working', :path => '/working'},
    {:name => 'Pending', :path => '/pending'},
    {:name => 'Failed', :path => '/failed'}
  ]
end

#url_path(*path_parts) ⇒ Object Also known as: u



51
52
53
# File 'lib/supervisor/application/app.rb', line 51

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