Class: Logical::Naf::Machine
- Inherits:
-
Object
- Object
- Logical::Naf::Machine
show all
- Includes:
- ActionView::Helpers::DateHelper
- Defined in:
- app/models/logical/naf/machine.rb
Constant Summary
collapse
- COLUMNS =
[:id,
:server_name,
:server_address,
:server_note,
:enabled,
:process_pool_size,
:last_checked_schedules_at,
:last_seen_alive_at,
:log_level,
:affinities,
:marked_down]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(naf_machine) ⇒ Machine
Returns a new instance of Machine.
21
22
23
|
# File 'app/models/logical/naf/machine.rb', line 21
def initialize(naf_machine)
@machine = naf_machine
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
25
26
27
28
29
30
31
|
# File 'app/models/logical/naf/machine.rb', line 25
def method_missing(method_name, *arguments, &block)
if @machine.respond_to?(method_name)
@machine.send(method_name, *arguments, &block)
else
super
end
end
|
Class Method Details
.all(filter = false) ⇒ Object
33
34
35
|
# File 'app/models/logical/naf/machine.rb', line 33
def self.all(filter = false)
::Naf::Machine.include_deleted(filter).all.map{ |machine| new(machine) }
end
|
Instance Method Details
#affinities ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/models/logical/naf/machine.rb', line 61
def affinities
@machine.machine_affinity_slots.map do |slot|
if slot.affinity_short_name
if slot.affinity_parameter.present? && slot.affinity_parameter > 0
slot.affinity_short_name + "(#{slot.affinity_parameter})"
else
slot.affinity_short_name
end
else
name = slot.affinity_classification_name + '_' + slot.affinity_name
name = name + '_required' if slot.required
name
end
end.join(", \n")
end
|
#last_checked_schedules_at ⇒ Object
41
42
43
44
45
46
47
|
# File 'app/models/logical/naf/machine.rb', line 41
def last_checked_schedules_at
if value = @machine.last_checked_schedules_at
"#{time_ago_in_words(value, true)} ago, #{value.localtime.strftime("%Y-%m-%d %r")}"
else
""
end
end
|
#last_seen_alive_at ⇒ Object
49
50
51
52
53
54
55
|
# File 'app/models/logical/naf/machine.rb', line 49
def last_seen_alive_at
if value = @machine.last_seen_alive_at
"#{time_ago_in_words(value, true)} ago, #{value.localtime.strftime("%Y-%m-%d %r")}"
else
""
end
end
|
#name ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'app/models/logical/naf/machine.rb', line 77
def name
if @machine.short_name
@machine.short_name
elsif @machine.server_name
@machine.server_name
else
@machine.server_address
end
end
|
#process_pool_size ⇒ Object
37
38
39
|
# File 'app/models/logical/naf/machine.rb', line 37
def process_pool_size
thread_pool_size
end
|
#runner ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/models/logical/naf/machine.rb', line 109
def runner
if @machine.server_name.present?
@machine.server_name.to_s
else
if Rails.env == 'development'
"localhost:#{Rails::Server.new.options[:Port]}"
else
@machine.server_address
end
end
end
|
#status ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/models/logical/naf/machine.rb', line 87
def status
runner_down = true
@machine.machine_runners.each do |runner|
if runner.machine_runner_invocations.where(wind_down_at: nil, dead_at: nil).count > 0
runner_down = false
break;
end
end
status = 'Good'
if runner_down
notes = 'Runner down'
status = 'Bad'
else
notes = ''
end
{ server_name: name,
status: status,
notes: notes }
end
|
#to_hash ⇒ Object
57
58
59
|
# File 'app/models/logical/naf/machine.rb', line 57
def to_hash
Hash[COLUMNS.map{ |m| [m, send(m)] }]
end
|