Class: Jiggler::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/jiggler/web.rb

Constant Summary collapse

WEB_PATH =
File.expand_path("#{File.dirname(__FILE__)}/web")
LAYOUT =
"#{WEB_PATH}/views/application.erb"
STYLESHEET =
"#{WEB_PATH}/assets/stylesheets/application.css"

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
# File 'lib/jiggler/web.rb', line 9

def call(env)
  @summary_instance = Jiggler::Summary.new(Jiggler.config)
  @summary = @summary_instance.all
  compiled_template = ERB.new(File.read(LAYOUT)).result(binding)
  [200, {}, [compiled_template]]
end

#format_args(args) ⇒ Object



65
66
67
68
# File 'lib/jiggler/web.rb', line 65

def format_args(args)
  return if args.nil?
  args.map { |arg| Oj.dump(arg, mode: :compat) }.join(', ')
end

#format_datetime(timestamp) ⇒ Object



28
29
30
31
# File 'lib/jiggler/web.rb', line 28

def format_datetime(timestamp)
  return if timestamp.nil?
  Time.at(timestamp.to_f).to_datetime
end

#format_memory(kb) ⇒ Object



33
34
35
36
# File 'lib/jiggler/web.rb', line 33

def format_memory(kb)
  return '?' if kb.nil?
  "#{(kb/1024.0).round(2)} MB"
end

#heartbeat_class(timestamp) ⇒ Object



55
56
57
# File 'lib/jiggler/web.rb', line 55

def heartbeat_class(timestamp)
  return 'outdated' if outdated_heartbeat?(timestamp)
end

#last_5_dead_jobsObject



16
17
18
# File 'lib/jiggler/web.rb', line 16

def last_5_dead_jobs
  @summary_instance.last_dead_jobs(5)
end

#last_5_retry_jobsObject



20
21
22
# File 'lib/jiggler/web.rb', line 20

def last_5_retry_jobs
  @summary_instance.last_retry_jobs(5)
end

#last_5_scheduled_jobsObject



24
25
26
# File 'lib/jiggler/web.rb', line 24

def last_5_scheduled_jobs
  @summary_instance.last_scheduled_jobs(5)
end

#outdated_heartbeat?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/jiggler/web.rb', line 59

def outdated_heartbeat?(timestamp)
  return true if timestamp.nil?
  seconds = Time.now.to_i - timestamp.to_i
  seconds > Jiggler.config[:stats_interval] * 2
end

#poller_badge(poller_enabled) ⇒ Object



70
71
72
# File 'lib/jiggler/web.rb', line 70

def poller_badge(poller_enabled)
  poller_enabled ? '<span class=\'badge badge-success\'>Polling</span>' : '<span class=\'badge\'>Polling Disabled</span>'
end

#stylesObject



74
75
76
# File 'lib/jiggler/web.rb', line 74

def styles
  @styles ||= File.read(STYLESHEET)
end

#time_ago_in_words(timestamp) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jiggler/web.rb', line 38

def time_ago_in_words(timestamp)
  return if timestamp.nil?
  seconds = Time.now.to_i - timestamp.to_i
  case seconds
  when 0..59
    "#{seconds} seconds ago"
  when 60..3599
    "#{(seconds/60).round} minutes ago"
  when 3600..86399
    "#{(seconds/3600).round} hours ago"
  when 86400..604799
    "#{(seconds/86400).round} days ago"
  else
    "#{(seconds/604800).round} weeks ago"
  end
end