Class: OpenC3::TriggerGroupMicroservice
- Inherits:
-
Microservice
- Object
- Microservice
- OpenC3::TriggerGroupMicroservice
- Defined in:
- lib/openc3/microservices/trigger_group_microservice.rb
Overview
The trigger microservice starts a manager then gets the activities from the sorted set in redis and updates the schedule for the manager. Timeline will then wait for an update on the timeline stream this will trigger an update again to the schedule.
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#manager_thread ⇒ Object
readonly
Returns the value of attribute manager_thread.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#share ⇒ Object
readonly
Returns the value of attribute share.
Attributes inherited from Microservice
#count, #custom, #error, #logger, #microservice_status_thread, #secrets, #state
Instance Method Summary collapse
- #block_for_updates ⇒ Object
-
#created_trigger_event(data) ⇒ Object
Add the trigger to the share.
-
#deleted_trigger_event(data) ⇒ Object
Remove the trigger from the share.
-
#initialize(*args) ⇒ TriggerGroupMicroservice
constructor
A new instance of TriggerGroupMicroservice.
- #no_op(data) ⇒ Object
- #refresh_event(data) ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
- #topic_lookup_functions ⇒ Object
Methods inherited from Microservice
Constructor Details
#initialize(*args) ⇒ TriggerGroupMicroservice
Returns a new instance of TriggerGroupMicroservice.
537 538 539 540 541 542 543 544 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 537 def initialize(*args) super(*args) @group = TriggerGroupShare.get_group(name: @name) @share = TriggerGroupShare.new(scope: @scope) @manager = TriggerGroupManager.new(name: @name, logger: @logger, scope: @scope, group: @group, share: @share) @manager_thread = nil @read_topic = true end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def group @group end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def manager @manager end |
#manager_thread ⇒ Object (readonly)
Returns the value of attribute manager_thread.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def manager_thread @manager_thread end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def scope @scope end |
#share ⇒ Object (readonly)
Returns the value of attribute share.
535 536 537 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 535 def share @share end |
Instance Method Details
#block_for_updates ⇒ Object
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 572 def block_for_updates @read_topic = true while @read_topic begin AutonomicTopic.read_topics(@topics) do |_topic, _msg_id, msg_hash, _redis| @logger.debug "TriggerGroupMicroservice block_for_updates: #{msg_hash.to_s}" if msg_hash['type'] == 'trigger' data = JSON.parse(msg_hash['data'], :allow_nan => true, :create_additions => true) public_send(topic_lookup_functions[msg_hash['kind']], data) end end rescue StandardError => e @logger.error "TriggerGroupMicroservice failed to read topics #{@topics}\n#{e.formatted}" end end end |
#created_trigger_event(data) ⇒ Object
Add the trigger to the share.
599 600 601 602 603 604 605 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 599 def created_trigger_event(data) @logger.debug "TriggerGroupMicroservice created_trigger_event #{data}" if data['group'] == @group @share.trigger_base.add(trigger: data) @manager.refresh() end end |
#deleted_trigger_event(data) ⇒ Object
Remove the trigger from the share.
608 609 610 611 612 613 614 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 608 def deleted_trigger_event(data) @logger.debug "TriggerGroupMicroservice deleted_trigger_event #{data}" if data['group'] == @group @share.trigger_base.remove(trigger: data) @manager.refresh() end end |
#no_op(data) ⇒ Object
589 590 591 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 589 def no_op(data) @logger.debug "TriggerGroupMicroservice web socket event: #{data}" end |
#refresh_event(data) ⇒ Object
593 594 595 596 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 593 def refresh_event(data) @logger.debug "TriggerGroupMicroservice web socket schedule refresh: #{data}" @read_topic = false end |
#run ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 546 def run @logger.info "TriggerGroupMicroservice running" @manager_thread = Thread.new { @manager.run } loop do triggers = TriggerModel.all(scope: @scope, group: @group) @share.trigger_base.update(triggers: triggers) break if @cancel_thread block_for_updates() break if @cancel_thread end @logger.info "TriggerGroupMicroservice exiting" end |
#shutdown ⇒ Object
616 617 618 619 620 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 616 def shutdown @read_topic = false @manager.shutdown() super end |
#topic_lookup_functions ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 560 def topic_lookup_functions return { 'created' => :created_trigger_event, 'updated' => :created_trigger_event, 'deleted' => :deleted_trigger_event, 'enabled' => :created_trigger_event, 'disabled' => :created_trigger_event, 'activated' => :created_trigger_event, 'deactivated' => :created_trigger_event, } end |