Class: Naf::MachineRunnerInvocation

Inherits:
NafBase
  • Object
show all
Defined in:
app/models/naf/machine_runner_invocation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NafBase

full_table_name_prefix

Class Method Details

.choose(filter) ⇒ Object


*** Class Methods *** ++++++++++++++++++++++



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/naf/machine_runner_invocation.rb', line 34

def self.choose(filter)
  if filter.present? && filter == 'top'
    return joins(
      "JOIN (
        SELECT
          machine_runner_id, max(created_at) as created_at
        FROM
          #{::Naf.schema_name}.machine_runner_invocations
        GROUP BY
          machine_runner_id
        ) AS mri2
      ON #{::Naf.schema_name}.machine_runner_invocations.created_at = mri2.created_at AND
        #{::Naf.schema_name}.machine_runner_invocations.machine_runner_id = mri2.machine_runner_id"
    )
  else
    return where({})
  end
end

.recently_marked_dead(time) ⇒ Object



53
54
55
56
57
58
# File 'app/models/naf/machine_runner_invocation.rb', line 53

def self.recently_marked_dead(time)
  where("
    #{::Naf.schema_name}.machine_runner_invocations.dead_at IS NOT NULL AND
    #{::Naf.schema_name}.machine_runner_invocations.dead_at > ?", Time.zone.now - time
  )
end

Instance Method Details

#statusObject


*** Instance Methods *** +++++++++++++++++++++++++



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/naf/machine_runner_invocation.rb', line 64

def status
  if self.dead_at.blank?
    if self.wind_down_at.present?
      # Runner is Waiting for jobs to finish running,
      # and will not start any other jobs
      'winding-down'
    else
      'running' # Runner is UP
    end
  else
    'dead' # Runner is DOWN
  end
end