module Sidekiq::Hierarchy::Web::Helpers

Constants

COLLAPSED_SUBTREE_THRESHOLD
TIME_TO_WORD

Public Instance Methods

bootstrap_status(status) click to toggle source

HUMANIZATION HELPERS

# 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) click to toggle source

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

Calls superclass method
# 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) click to toggle source

ROUTE HELPERS

# 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) click to toggle source

FORMATTING HELPERS

# File lib/sidekiq/hierarchy/web/helpers.rb, line 55
def safe_relative_time(timestamp)
  timestamp.nil? ? '-' : relative_time(timestamp)
end
status_in_words(job) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/sidekiq/hierarchy/web/helpers.rb, line 44
def workflow_url(workflow=nil)
  "#{root_path}hierarchy/workflows/#{workflow.jid if workflow}"
end