Module: Sidekiq::Hierarchy::Web::Helpers

Defined in:
lib/sidekiq/hierarchy/web/helpers.rb

Constant Summary collapse

TIME_TO_WORD =
{
  29030400 => 'year',
  2419200 => 'month',
  604800 => 'week',
  86400 => 'day',
  3600 => 'hour',
  60 => 'minute',
  1 => 'second',
}
COLLAPSED_SUBTREE_THRESHOLD =
500

Instance Method Summary collapse

Instance Method Details

#bootstrap_status(status) ⇒ Object

HUMANIZATION HELPERS



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 69

def bootstrap_status(status)
  case status
  when :enqueued, :requeued
    'warning'
  when :running
    'info'
  when :complete
    'success'
  when :failed
    'danger'
  end
end

#find_template(views, name, engine, &block) ⇒ Object

Override find_template logic to process arrays of view directories warning: this may be incompatible with other overrides of find_template, though that really shouldn’t happen if they match the method contract



23
24
25
26
27
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 23

def find_template(views, name, engine, &block)
  Array(views).each do |view_dir|
    super(view_dir, name, engine, &block)
  end
end

#job_url(job = nil) ⇒ Object

ROUTE HELPERS



40
41
42
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 40

def job_url(job=nil)
  "#{root_path}hierarchy/jobs/#{job.jid if job}"
end

#safe_relative_time(timestamp) ⇒ Object

FORMATTING HELPERS



55
56
57
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 55

def safe_relative_time(timestamp)
  timestamp.nil? ? '-' : relative_time(timestamp)
end

#status_in_words(job) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 82

def status_in_words(job)
  case job.status
  when :enqueued
    "enqueued #{safe_relative_time(job.enqueued_at)}"
  when :requeued
    "requeued #{safe_relative_time(job.enqueued_at)}"
  when :running
    "running #{time_in_words(Time.now - job.run_at)}"
  when :complete
    "complete in #{time_in_words(job.complete_at - job.run_at)}"
  when :failed
    "failed in #{time_in_words(job.failed_at - job.run_at)}"
  end
end

#subtree_template(job) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 29

def subtree_template(job)
  if job.subtree_size > COLLAPSED_SUBTREE_THRESHOLD
    :_job_tree_collapsed
  else
    :_job_tree_node
  end
end

#time_in_words(time) ⇒ Object



59
60
61
62
63
64
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 59

def time_in_words(time)
  divisor, period = TIME_TO_WORD.select { |secs, _| time.ceil >= secs }.max_by(&:first)
  duration = (time / divisor).to_i

  "#{duration} #{period}#{'s' unless duration == 1}"
end

#workflow_set_url(status) ⇒ Object



48
49
50
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 48

def workflow_set_url(status)
  "#{root_path}hierarchy/workflow_sets/#{status}"
end

#workflow_url(workflow = nil) ⇒ Object



44
45
46
# File 'lib/sidekiq/hierarchy/web/helpers.rb', line 44

def workflow_url(workflow=nil)
  "#{root_path}hierarchy/workflows/#{workflow.jid if workflow}"
end