Class: Kaal::Dispatch::MemoryEngine
- Defined in:
- lib/kaal/dispatch/memory_engine.rb
Overview
In-memory dispatch registry using a Hash for storage.
Stores dispatch records in memory. Suitable for development, testing, or single-node deployments where persistence is not required.
Instance Method Summary collapse
-
#clear ⇒ void
Clear all stored dispatch records.
-
#find_dispatch(key, fire_time) ⇒ Hash?
Find a dispatch record for a specific job and fire time.
-
#initialize ⇒ MemoryEngine
constructor
Initialize a new in-memory registry.
-
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Hash
Log a dispatch attempt in memory.
-
#size ⇒ Integer
Get the number of stored dispatch records.
Methods inherited from Registry
Constructor Details
#initialize ⇒ MemoryEngine
Initialize a new in-memory registry.
25 26 27 28 29 |
# File 'lib/kaal/dispatch/memory_engine.rb', line 25 def initialize super @dispatches = {} @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clear all stored dispatch records. Useful for testing.
70 71 72 73 74 |
# File 'lib/kaal/dispatch/memory_engine.rb', line 70 def clear @mutex.synchronize do @dispatches.clear end end |
#find_dispatch(key, fire_time) ⇒ Hash?
Find a dispatch record for a specific job and fire time.
58 59 60 61 62 63 |
# File 'lib/kaal/dispatch/memory_engine.rb', line 58 def find_dispatch(key, fire_time) @mutex.synchronize do storage_key = build_key(key, fire_time) @dispatches[storage_key] end end |
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Hash
Log a dispatch attempt in memory.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kaal/dispatch/memory_engine.rb', line 39 def log_dispatch(key, fire_time, node_id, status = 'dispatched') @mutex.synchronize do storage_key = build_key(key, fire_time) @dispatches[storage_key] = { key: key, fire_time: fire_time, dispatched_at: Time.current, node_id: node_id, status: status } end end |
#size ⇒ Integer
Get the number of stored dispatch records.
80 81 82 83 84 |
# File 'lib/kaal/dispatch/memory_engine.rb', line 80 def size @mutex.synchronize do @dispatches.size end end |