Class: OpenC3::LimitsResponseThread
- Defined in:
- lib/openc3/microservices/decom_microservice.rb
Instance Method Summary collapse
- #graceful_kill ⇒ Object
-
#initialize(microservice_name:, queue:, logger:, metric:, scope:) ⇒ LimitsResponseThread
constructor
A new instance of LimitsResponseThread.
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(microservice_name:, queue:, logger:, metric:, scope:) ⇒ LimitsResponseThread
Returns a new instance of LimitsResponseThread.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 32 def initialize(microservice_name:, queue:, logger:, metric:, scope:) @microservice_name = microservice_name @queue = queue @logger = logger @metric = metric @scope = scope @count = 0 @error_count = 0 @metric.set(name: 'limits_response_total', value: @count, type: 'counter') @metric.set(name: 'limits_response_error_total', value: @error_count, type: 'counter') end |
Instance Method Details
#graceful_kill ⇒ Object
61 62 63 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 61 def graceful_kill @queue << [nil, nil, nil] end |
#run ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 65 def run while true packet, item, old_limits_state = @queue.pop() break if packet.nil? begin item.limits.response.call(packet, item, old_limits_state) rescue Exception => e @error_count += 1 @metric.set(name: 'limits_response_error_total', value: @error_count, type: 'counter') @logger.error "#{packet.target_name} #{packet.packet_name} #{item.name} Limits Response Exception!" @logger.error "Called with old_state = #{old_limits_state}, new_state = #{item.limits.state}" @logger.error e.filtered end @count += 1 @metric.set(name: 'limits_response_total', value: @count, type: 'counter') end end |
#start ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 44 def start @thread = Thread.new do run() rescue Exception => e @logger.error "#{@microservice_name}: Limits Response thread died: #{e.formatted}" raise e end ThreadManager.instance.register(@thread, stop_object: self) end |
#stop ⇒ Object
54 55 56 57 58 59 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 54 def stop if @thread OpenC3.kill_thread(self, @thread) @thread = nil end end |