Class: HostStatus::ExecutionStatus

Inherits:
Status
  • Object
show all
Defined in:
app/models/host_status/execution_status.rb

Defined Under Namespace

Classes: ExecutionTaskStatusMapper

Constant Summary collapse

OK =

execution finished successfully

0
ERROR =

execution finished with error

1
QUEUED =

execution hasn’t started yet, either scheduled to future or executor didn’t create task yet

2
RUNNING =

execution is in progress, dynflow task was created

3
STATUS_NAMES =

mapping to string representation

{ OK => 'succeeded', ERROR => 'failed', QUEUED => 'queued', RUNNING => 'running' }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.status_nameObject



33
34
35
# File 'app/models/host_status/execution_status.rb', line 33

def self.status_name
  N_('Execution')
end

Instance Method Details

#relevant?(*args) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/host_status/execution_status.rb', line 13

def relevant?(*args)
  execution_tasks.present?
end

#to_global(options = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'app/models/host_status/execution_status.rb', line 25

def to_global(options = {})
  if to_status(options) == ERROR
    return HostStatus::Global::ERROR
  else
    return HostStatus::Global::OK
  end
end

#to_label(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/models/host_status/execution_status.rb', line 37

def to_label(options = {})
  case to_status(options)
    when OK
      execution_tasks.present? ? N_('Last execution succeeded') : N_('No execution finished yet')
    when ERROR
      N_('Last execution failed')
    else
      N_('Unknown execution status')
  end
end

#to_status(options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'app/models/host_status/execution_status.rb', line 17

def to_status(options = {})
  if self.new_record?
    ExecutionTaskStatusMapper.new(last_stopped_task).status
  else
    self.status
  end
end