Class: Yes::Core::Commands::Stateless::Handler
- Inherits:
-
Object
- Object
- Yes::Core::Commands::Stateless::Handler
- Includes:
- HandlerHelpers, OpenTelemetry::Trackable
- Defined in:
- lib/yes/core/commands/stateless/handler.rb
Overview
Handles stateless commands by publishing events to the event store without maintaining aggregate state in memory.
Defined Under Namespace
Modules: RevisionsLoader Classes: InvalidTransition, NoChangeTransition, TransitionError
Constant Summary collapse
- MISSING_CMDS_MSG =
'Commands missing'
Class Attribute Summary collapse
-
.event_name ⇒ Object
Returns the value of attribute event_name.
-
.streams ⇒ Object
Returns the value of attribute streams.
Instance Attribute Summary collapse
-
#publish_events ⇒ Object
readonly
Returns the value of attribute publish_events.
-
#revision_check ⇒ Object
readonly
Returns the value of attribute revision_check.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ void
- #initialize(cmd, events_cache: {}, revision_check: true, publish_events: true) ⇒ Stateless::Handler constructor
-
#publish_event(event_name) ⇒ PgEventstore::Event
Publishes a single event to the event store.
Methods included from HandlerHelpers
#activated?, #added?, #deactivated?, #disabled?, #enabled?, #event_exists_with_payload?, #event_in_stream?, #item_added?, #item_assigned?, #item_removed?, #item_unassigned?, #no_change?, #partial_payload_field_changed?, #published?, #removed?, #skip?, #unpublished?
Constructor Details
#initialize(cmd, events_cache: {}, revision_check: true, publish_events: true) ⇒ Stateless::Handler
86 87 88 89 90 91 92 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 86 def initialize(cmd, events_cache: {}, revision_check: true, publish_events: true) @cmd = cmd @cmd_helper = Commands::Helper.new(cmd) @revision_check = revision_check @publish_events = publish_events @events_cache = events_cache end |
Class Attribute Details
.event_name ⇒ Object
Returns the value of attribute event_name.
66 67 68 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 66 def event_name @event_name end |
.streams ⇒ Object
Returns the value of attribute streams.
66 67 68 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 66 def streams @streams end |
Instance Attribute Details
#publish_events ⇒ Object (readonly)
Returns the value of attribute publish_events.
74 75 76 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 74 def publish_events @publish_events end |
#revision_check ⇒ Object (readonly)
Returns the value of attribute revision_check.
74 75 76 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 74 def revision_check @revision_check end |
Class Method Details
.inherited(base) ⇒ Object
59 60 61 62 63 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 59 def self.inherited(base) super base.prepend(RevisionsLoader) end |
.stateless? ⇒ Boolean
69 70 71 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 69 def stateless? true end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
95 96 97 98 99 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 95 def call return unless publish_events publish_event(self.class.event_name) end |
#publish_event(event_name) ⇒ PgEventstore::Event
Publishes a single event to the event store
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/yes/core/commands/stateless/handler.rb', line 105 def publish_event(event_name) transaction.otl_contexts.publisher = self.class.propagate_context(service_name: true) if transaction&.otl_contexts type = event_type(event_name) event_class = events_module.const_get(event_name) event = event_class.new( type:, data: event_payload, metadata: ) otl_record_event_data(event) verify_revisions! if revision_check PgEventstore.client.append_to_stream( stream, event, options: { expected_revision: subject_stream_revision } ).tap { otl_record_response(_1) } end |