Class: Servus::Events::Invocation
- Inherits:
-
Object
- Object
- Servus::Events::Invocation
- Defined in:
- lib/servus/events/invocation.rb
Overview
A normalized, executable representation of "call this service with these params."
Routers return arrays of Invocation objects. The Bus collects them,
deduplicates by #key (first wins), and calls #execute on each.
An Invocation separates identity (service + params) from
scheduling (queue, priority, delay). The #key is derived only
from the identity — two invocations that call the same service with
the same params are considered duplicates regardless of their options.
Invocations are always enqueued, never run inline. A reaction that ran synchronously would put its latency and its failures back into the emitting service, which is what events exist to avoid.
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Scheduling options —
queue,wait,wait_until,priority,job_options. -
#params ⇒ Hash
readonly
Keyword arguments passed to the service.
-
#service ⇒ Class
readonly
The service class to enqueue (must respond to
.call_async).
Instance Method Summary collapse
-
#enqueue ⇒ void
Enqueues the invocation via ActiveJob.
-
#initialize(service:, params:, options: {}) ⇒ Invocation
constructor
A new instance of Invocation.
-
#key ⇒ String
A deterministic deduplication key derived from the service class and params.
Constructor Details
#initialize(service:, params:, options: {}) ⇒ Invocation
Returns a new instance of Invocation.
46 47 48 49 50 |
# File 'lib/servus/events/invocation.rb', line 46 def initialize(service:, params:, options: {}) @service = service @params = params @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns scheduling options — queue, wait, wait_until,
priority, job_options.
41 42 43 |
# File 'lib/servus/events/invocation.rb', line 41 def @options end |
#params ⇒ Hash (readonly)
Returns keyword arguments passed to the service.
37 38 39 |
# File 'lib/servus/events/invocation.rb', line 37 def params @params end |
#service ⇒ Class (readonly)
Returns the service class to enqueue (must respond to .call_async).
34 35 36 |
# File 'lib/servus/events/invocation.rb', line 34 def service @service end |
Instance Method Details
#enqueue ⇒ void
This method returns an undefined value.
Enqueues the invocation via ActiveJob.
Scheduling options (queue, wait, priority, and so on) are merged into
the call_async keyword arguments.
59 60 61 62 63 |
# File 'lib/servus/events/invocation.rb', line 59 def enqueue raise Errors::AsyncBackendMissingError.for(service) unless service.respond_to?(:call_async) service.call_async(**params, **) end |
#key ⇒ String
A deterministic deduplication key derived from the service class and params. Two invocations with the same key are considered duplicates — the Bus keeps the first and skips the rest.
Options are intentionally excluded: identity is what to call, not how to call it.
73 74 75 |
# File 'lib/servus/events/invocation.rb', line 73 def key Digest::SHA256.hexdigest("#{service}:#{params.to_json}") end |