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.
Constant Summary collapse
- TOPIC_LOOKUP =
This lookup is mapping all the different trigger notifications which are primarily sent by notify in TriggerModel
{ 'error' => :no_op, # Sent by TriggerGroupWorker 'created' => :created_trigger_event, 'updated' => :rebuild_trigger_event, 'deleted' => :deleted_trigger_event, 'enabled' => :updated_trigger_event, 'disabled' => :updated_trigger_event, 'true' => :no_op, # Sent by TriggerGroupWorker 'false' => :no_op, # Sent by TriggerGroupWorker }
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
-
#rebuild_trigger_event(data) ⇒ Object
When a trigger is updated it could change items which modifies topics and potentially adds or removes topics so refresh everything just to be safe.
- #run ⇒ Object
- #shutdown ⇒ Object
- #updated_trigger_event(data) ⇒ Object
Methods inherited from Microservice
Constructor Details
#initialize(*args) ⇒ TriggerGroupMicroservice
Returns a new instance of TriggerGroupMicroservice.
604 605 606 607 608 609 610 611 612 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 604 def initialize(*args) super(*args) # The name is passed in via the trigger_group_model as "#{scope}__TRIGGER_GROUP__#{name}" @group = @name.split('__')[2] @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.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def group @group end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def manager @manager end |
#manager_thread ⇒ Object (readonly)
Returns the value of attribute manager_thread.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def manager_thread @manager_thread end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def scope @scope end |
#share ⇒ Object (readonly)
Returns the value of attribute share.
590 591 592 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 590 def share @share end |
Instance Method Details
#block_for_updates ⇒ Object
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 628 def block_for_updates @read_topic = true while @read_topic && !@cancel_thread begin AutonomicTopic.read_topics(@topics) do |_topic, _msg_id, msg_hash, _redis| break if @cancel_thread @logger.debug "TriggerGroupMicroservice block_for_updates: #{msg_hash.to_s}" # Process trigger notifications created by TriggerModel notify if msg_hash['type'] == 'trigger' data = JSON.parse(msg_hash['data'], :allow_nan => true, :create_additions => true) public_send(TOPIC_LOOKUP[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.
652 653 654 655 656 657 658 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 652 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.
678 679 680 681 682 683 684 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 678 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
647 648 649 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 647 def no_op(data) @logger.debug "TriggerGroupMicroservice web socket event: #{data}" end |
#rebuild_trigger_event(data) ⇒ Object
When a trigger is updated it could change items which modifies topics and potentially adds or removes topics so refresh everything just to be safe
669 670 671 672 673 674 675 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 669 def rebuild_trigger_event(data) @logger.debug "TriggerGroupMicroservice rebuild_trigger_event #{data}" if data['group'] == @group @share.trigger_base.update(trigger: data) @read_topic = false end end |
#run ⇒ Object
614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 614 def run @logger.info "TriggerGroupMicroservice running" @manager_thread = Thread.new { @manager.run } loop do triggers = TriggerModel.all(scope: @scope, group: @group) @share.trigger_base.rebuild(triggers: triggers) @manager.refresh() # Everytime we do a full base update we refesh the manager break if @cancel_thread block_for_updates() break if @cancel_thread end @logger.info "TriggerGroupMicroservice exiting" end |
#shutdown ⇒ Object
686 687 688 689 690 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 686 def shutdown @read_topic = false @manager.shutdown() super end |
#updated_trigger_event(data) ⇒ Object
660 661 662 663 664 665 |
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 660 def updated_trigger_event(data) @logger.debug "TriggerGroupMicroservice updated_trigger_event #{data}" if data['group'] == @group @share.trigger_base.update(trigger: data) end end |