Class: Kaal::Dispatch::RedisEngine
- Defined in:
- lib/kaal/dispatch/redis_engine.rb
Overview
Redis-backed dispatch registry.
Stores dispatch records in Redis as JSON-serialized values. Keys are automatically expired based on TTL to prevent unbounded growth.
Constant Summary collapse
- DEFAULT_TTL =
Default TTL for dispatch records (7 days in seconds)
7 * 24 * 60 * 60
Instance Method Summary collapse
-
#find_dispatch(key, fire_time) ⇒ Hash?
Find a dispatch record for a specific job and fire time.
-
#initialize(redis, namespace: 'kaal', ttl: DEFAULT_TTL) ⇒ RedisEngine
constructor
Initialize a new Redis-backed registry.
-
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Hash
Log a dispatch attempt in Redis.
Methods inherited from Registry
Constructor Details
#initialize(redis, namespace: 'kaal', ttl: DEFAULT_TTL) ⇒ RedisEngine
Initialize a new Redis-backed registry.
32 33 34 35 36 37 |
# File 'lib/kaal/dispatch/redis_engine.rb', line 32 def initialize(redis, namespace: 'kaal', ttl: DEFAULT_TTL) super() @redis = redis @namespace = namespace @ttl = ttl end |
Instance Method Details
#find_dispatch(key, fire_time) ⇒ Hash?
Find a dispatch record for a specific job and fire time.
67 68 69 70 71 72 73 74 |
# File 'lib/kaal/dispatch/redis_engine.rb', line 67 def find_dispatch(key, fire_time) redis_key = build_redis_key(key, fire_time) value = @redis.get(redis_key) return nil unless value record = JSON.parse(value, symbolize_names: true) (record) end |
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Hash
Log a dispatch attempt in Redis.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kaal/dispatch/redis_engine.rb', line 47 def log_dispatch(key, fire_time, node_id, status = 'dispatched') redis_key = build_redis_key(key, fire_time) record = { key: key, fire_time: fire_time.to_i, dispatched_at: Time.now.utc.to_i, node_id: node_id, status: status } @redis.setex(redis_key, @ttl, JSON.generate(record)) record end |