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 *execution strategy* (async, queue, priority, etc.). 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.
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Execution options —
async,queue,wait,wait_until,priority,job_options. -
#params ⇒ Hash
readonly
Keyword arguments passed to the service.
-
#service ⇒ Class
readonly
The service class to call (must respond to
.callor.call_async).
Instance Method Summary collapse
-
#execute ⇒ Servus::Support::Response, void
Executes the invocation.
-
#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.
50 51 52 53 54 |
# File 'lib/servus/events/invocation.rb', line 50 def initialize(service:, params:, options: {}) @service = service @params = params @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns execution options — async, queue, wait, wait_until, priority, job_options.
45 46 47 |
# File 'lib/servus/events/invocation.rb', line 45 def @options end |
#params ⇒ Hash (readonly)
Returns keyword arguments passed to the service.
41 42 43 |
# File 'lib/servus/events/invocation.rb', line 41 def params @params end |
#service ⇒ Class (readonly)
Returns the service class to call (must respond to .call or .call_async).
38 39 40 |
# File 'lib/servus/events/invocation.rb', line 38 def service @service end |
Instance Method Details
#execute ⇒ Servus::Support::Response, void
Executes the invocation.
Delegates to service.call for synchronous invocations or service.call_async for asynchronous ones. Async scheduling options (queue, wait, priority, etc.) are merged into the call_async kwargs.
64 65 66 67 68 69 70 |
# File 'lib/servus/events/invocation.rb', line 64 def execute if [:async] service.call_async(**params, **) else service.call(**params) end 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.
80 81 82 |
# File 'lib/servus/events/invocation.rb', line 80 def key Digest::SHA256.hexdigest("#{service}:#{params.to_json}") end |