Class: Textus::Dispatch::Middleware::Cascade
- Inherits:
-
Base
- Object
- Base
- Textus::Dispatch::Middleware::Cascade
show all
- Defined in:
- lib/textus/dispatch/middleware/cascade.rb
Constant Summary
collapse
- CASCADE_VERBS =
%i[put propose accept reject key_mv key_delete].freeze
- TRIGGER_TYPE_MAP =
{
Contracts::PutEntry => "entry.written",
Contracts::ProposeEntry => "entry.written",
Contracts::DeleteKey => "entry.deleted",
Contracts::MoveKey => "entry.moved",
Contracts::AcceptProposal => "proposal.accepted",
Contracts::RejectProposal => "proposal.rejected",
}.freeze
Instance Method Summary
collapse
Methods inherited from Base
inherited, middleware_name
Instance Method Details
#call(container:, command:, call:, next_handler:) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/textus/dispatch/middleware/cascade.rb', line 18
def call(container:, command:, call:, next_handler:)
result = next_handler.call(command, call)
return result unless result.success? && cascadable?(command)
key = cascade_key(command)
return result unless key
trigger_type = TRIGGER_TYPE_MAP[command.class]
jobs = Textus::Store::Jobs::Planner.new(container: container).plan(
trigger: { "type" => trigger_type, "target" => key },
role: call.role,
)
queue = Textus::Store::Jobs::Queue.new(store: container.job_store)
jobs.each { |j| queue.enqueue(j) }
result
end
|