Module: JobInvocationsChartHelper

Included in:
JobInvocationsController
Defined in:
app/helpers/job_invocations_chart_helper.rb

Overview

frozen_string_literal:true

Instance Method Summary collapse

Instance Method Details

#job_invocation_cancelled_statusObject



67
68
69
70
71
# File 'app/helpers/job_invocations_chart_helper.rb', line 67

def job_invocation_cancelled_status
  icon_text('close',
    @job_invocation_data[3][1],
    :kind => 'pficon')
end

#job_invocation_chart(invocation) ⇒ Object



4
5
6
7
8
# File 'app/helpers/job_invocations_chart_helper.rb', line 4

def job_invocation_chart(invocation)
  donut_chart('#status_chart',
    job_invocation_data(invocation)[:columns],
    job_invocation_data(invocation)[:groups])
end

#job_invocation_data(invocation) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/job_invocations_chart_helper.rb', line 10

def job_invocation_data(invocation)
  return @job_invocation_data if @job_invocation_data.present?

  progress_report = invocation.progress_report
  success = progress_report[:success]
  cancelled = progress_report[:cancelled]
  failed = progress_report[:error]
  pending = progress_report[:pending]
  columns = [[_('Success'), success, '#5CB85C'],
             [_('Failed'), failed, '#D9534F'],
             [_('Pending'), pending, '#DEDEDE'],
             [_('Cancelled'), cancelled, '#B7312D']]
  groups = [columns.map(&:first)]

  @job_invocation_data = { :columns => columns, :groups => groups}
end

#job_invocation_failed_statusObject



55
56
57
58
59
# File 'app/helpers/job_invocations_chart_helper.rb', line 55

def job_invocation_failed_status
  icon_text('error-circle-o',
    @job_invocation_data[1][1],
    :kind => 'pficon')
end

#job_invocation_pending_statusObject



61
62
63
64
65
# File 'app/helpers/job_invocations_chart_helper.rb', line 61

def job_invocation_pending_status
  icon_text('running',
    @job_invocation_data[2][1],
    :kind => 'pficon')
end

#job_invocation_status(invocation, percent = nil, verbose = true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/job_invocations_chart_helper.rb', line 27

def job_invocation_status(invocation, percent = nil, verbose = true)
  case invocation.status
  when HostStatus::ExecutionStatus::QUEUED
    if verbose && invocation.task
      _('queued to start executing in %{time}') % {:time => time_ago_in_words(invocation.task.start_at) }
    else
      _('queued')
    end
  when HostStatus::ExecutionStatus::RUNNING
    percent ||= invocation.progress_report[:progress]
    _('running %{percent}%%') % {:percent => percent}
  when HostStatus::ExecutionStatus::OK
    _('succeeded')
  when HostStatus::ExecutionStatus::CANCELLED
    _('cancelled')
  when HostStatus::ExecutionStatus::ERROR
    _('failed')
  else
    _('unknown status')
  end
end

#job_invocation_success_statusObject



49
50
51
52
53
# File 'app/helpers/job_invocations_chart_helper.rb', line 49

def job_invocation_success_status
  icon_text('ok',
    @job_invocation_data[0][1],
    :kind => 'pficon')
end

#task_cancelled?(task) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/helpers/job_invocations_chart_helper.rb', line 77

def task_cancelled?(task)
  task.execution_plan.errors.map(&:exception).any? { |exception| exception.class == ::ForemanTasks::Task::TaskCancelledException }
end

#task_failed?(task) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/helpers/job_invocations_chart_helper.rb', line 73

def task_failed?(task)
  %w(warning error).include? task.result
end