Class: RCS::HeartBeat::Base
- Inherits:
-
Object
- Object
- RCS::HeartBeat::Base
- Extended by:
- Tracer
- Includes:
- SystemStatusCodes, Tracer
- Defined in:
- lib/rcs-common/heartbeat.rb
Constant Summary
Constants included from Tracer
Constants included from SystemStatusCodes
SystemStatusCodes::ERROR, SystemStatusCodes::OK, SystemStatusCodes::WARN
Class Method Summary collapse
-
.component(component_name, component_fullname = nil) ⇒ Object
Declare the component To use as an helper in the subclasses.
-
.perform ⇒ Object
This method is called from outside.
Instance Method Summary collapse
-
#initialize(component_name, component_fullname: nil) ⇒ Base
constructor
A new instance of Base.
-
#perform ⇒ Object
Override this method.
- #update(status, message) ⇒ Object
Methods included from Tracer
thread_name, trace, trace_ensure_log_folders, trace_init, trace_named_put, trace_named_remove, trace_nested_pop, trace_nested_push, trace_setup
Constructor Details
#initialize(component_name, component_fullname: nil) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 40 41 |
# File 'lib/rcs-common/heartbeat.rb', line 35 def initialize(component_name, component_fullname: nil) raise("Undefined component version") unless version raise("Undefined component name") unless component_name @component_name = component_name.to_s.downcase @component_fullname = component_fullname || "RCS::#{component_name.to_s.capitalize}" end |
Class Method Details
.component(component_name, component_fullname = nil) ⇒ Object
Declare the component To use as an helper in the subclasses
13 14 15 16 |
# File 'lib/rcs-common/heartbeat.rb', line 13 def self.component(component_name, component_fullname = nil) @component_name = component_name @component_fullname = component_fullname end |
.perform ⇒ Object
This method is called from outside
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rcs-common/heartbeat.rb', line 19 def self.perform heartbeat = new(@component_name, component_fullname: @component_fullname) status, = *heartbeat.perform if status heartbeat.update(status, ) else # trace(:warn, "heartbeat prevented") end rescue Interrupt trace :fatal, "Heartbeat was interrupted because of a term signal" rescue Exception => ex trace :fatal, "Cannot perform heartbeat: #{ex.message}" trace :fatal, ex.backtrace end |
Instance Method Details
#perform ⇒ Object
Override this method
66 67 68 |
# File 'lib/rcs-common/heartbeat.rb', line 66 def perform end |
#update(status, message) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rcs-common/heartbeat.rb', line 43 def update(status, ) system_status, = * if status == OK and system_status != OK status, = system_status, end attributes = [@component_fullname, hostname, status, , machine_stats, @component_name, version] if defined?(::Status) # Db ::Status.status_update(*attributes) else # Collector db_class = Object.const_get(@component_fullname)::DB attributes[1] = '' db_class.instance.update_status(*attributes) end ensure end |