Class: Cosmos::RouterTlmHandlerThread
- Defined in:
- lib/cosmos/microservices/interface_microservice.rb
Instance Method Summary collapse
- #graceful_kill ⇒ Object
-
#initialize(router, tlm, scope:) ⇒ RouterTlmHandlerThread
constructor
A new instance of RouterTlmHandlerThread.
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(router, tlm, scope:) ⇒ RouterTlmHandlerThread
Returns a new instance of RouterTlmHandlerThread.
163 164 165 166 167 |
# File 'lib/cosmos/microservices/interface_microservice.rb', line 163 def initialize(router, tlm, scope:) @router = router @tlm = tlm @scope = scope end |
Instance Method Details
#graceful_kill ⇒ Object
182 183 184 |
# File 'lib/cosmos/microservices/interface_microservice.rb', line 182 def graceful_kill RouterTopic.shutdown(@router, scope: @scope) end |
#run ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/cosmos/microservices/interface_microservice.rb', line 186 def run RouterTopic.receive_telemetry(@router, scope: @scope) do |topic, msg_hash| # Check for commands to the router itself if /CMD}ROUTER/.match?(topic) if msg_hash['shutdown'] Logger.info "#{@router.name}: Shutdown requested" return end if msg_hash['connect'] Logger.info "#{@router.name}: Connect requested" @tlm.attempting() end if msg_hash['disconnect'] Logger.info "#{@router.name}: Disconnect requested" @tlm.disconnect(false) end if msg_hash.key?('log_raw') if msg_hash['log_raw'] == 'true' Logger.info "#{@router.name}: Enable raw logging" @router.start_raw_logging else Logger.info "#{@router.name}: Disable raw logging" @router.stop_raw_logging end end next 'SUCCESS' end if @router.connected? target_name = msg_hash["target_name"] packet_name = msg_hash["packet_name"] packet = System.telemetry.packet(target_name, packet_name) packet.stored = ConfigParser.handle_true_false(msg_hash["stored"]) packet.received_time = Time.from_nsec_from_epoch(msg_hash["time"].to_i) packet.received_count = msg_hash["received_count"].to_i packet.buffer = msg_hash["buffer"] begin @router.write(packet) RouterStatusModel.set(@router.as_json, scope: @scope) next 'SUCCESS' rescue => e Logger.error "#{@router.name}: #{e.formatted}" next e. end end end end |
#start ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/cosmos/microservices/interface_microservice.rb', line 169 def start @thread = Thread.new do run() rescue Exception => err Logger.error "#{@router.name}: Telemetry handler thread died: #{err.formatted}" raise err end end |
#stop ⇒ Object
178 179 180 |
# File 'lib/cosmos/microservices/interface_microservice.rb', line 178 def stop Cosmos.kill_thread(self, @thread) end |