class HostStatus::ExecutionStatus

def self.status_name

def self.status_name
  N_('Execution')
end

def execution_tasks

def execution_tasks
  ForemanTasks::Task::DynflowTask.for_action(Actions::RemoteExecution::RunHostJob).for_resource(host)
end

def last_stopped_task

def last_stopped_task
  @last_stopped_task ||= execution_tasks.order(:started_at).where(:state => 'stopped').last
end

def relevant?(*args)

def relevant?(*args)
  host.get_status(HostStatus::ExecutionStatus).present?
end

def status_link

def status_link
  job_invocation = last_stopped_task&.parent_task&.job_invocations&.first
  return unless job_invocation
  return nil unless User.current.can?(:view_job_invocations, job_invocation)
  Rails.application.routes.url_helpers.job_invocation_path(job_invocation)
end

def to_global(options = {})

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

def to_label(options = {})

def to_label(options = {})
  case to_status(options)
    when OK
      N_('Last execution succeeded')
    when CANCELLED
      N_('Last execution cancelled')
    when ERROR
      N_('Last execution failed')
    else
      N_('Unknown execution status')
  end
end

def to_status(options = {})

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