Class: Kaal::Dispatch::DatabaseEngine
- Defined in:
- lib/kaal/dispatch/database_engine.rb
Overview
Database-backed dispatch registry using ActiveRecord.
Stores dispatch records in the database using the CronDispatch model. Provides persistent, queryable audit logs across all nodes.
Instance Method Summary collapse
-
#cleanup(recovery_window: 86_400) ⇒ Integer
Delete old dispatch records older than the specified time.
-
#find_by_key(key) ⇒ ActiveRecord::Relation
Find all dispatch records for a specific job key.
-
#find_by_node(node_id) ⇒ ActiveRecord::Relation
Find all dispatch records by node ID.
-
#find_by_status(status) ⇒ ActiveRecord::Relation
Find all dispatch records with a specific status.
-
#find_dispatch(key, fire_time) ⇒ Kaal::CronDispatch?
Find a dispatch record for a specific job and fire time.
-
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Kaal::CronDispatch
Log a dispatch attempt in the database.
Methods inherited from Registry
Instance Method Details
#cleanup(recovery_window: 86_400) ⇒ Integer
Delete old dispatch records older than the specified time.
This cleanup prevents unbounded database growth by removing records that are older than the recovery window, making them irrelevant for future recovery operations.
88 89 90 91 |
# File 'lib/kaal/dispatch/database_engine.rb', line 88 def cleanup(recovery_window: 86_400) cutoff_time = Time.current - recovery_window ::Kaal::CronDispatch.where('fire_time < ?', cutoff_time).delete_all end |
#find_by_key(key) ⇒ ActiveRecord::Relation
Find all dispatch records for a specific job key.
57 58 59 |
# File 'lib/kaal/dispatch/database_engine.rb', line 57 def find_by_key(key) ::Kaal::CronDispatch.where(key: key).order(fire_time: :desc) end |
#find_by_node(node_id) ⇒ ActiveRecord::Relation
Find all dispatch records by node ID.
66 67 68 |
# File 'lib/kaal/dispatch/database_engine.rb', line 66 def find_by_node(node_id) ::Kaal::CronDispatch.where(node_id: node_id).order(fire_time: :desc) end |
#find_by_status(status) ⇒ ActiveRecord::Relation
Find all dispatch records with a specific status.
75 76 77 |
# File 'lib/kaal/dispatch/database_engine.rb', line 75 def find_by_status(status) ::Kaal::CronDispatch.where(status: status).order(fire_time: :desc) end |
#find_dispatch(key, fire_time) ⇒ Kaal::CronDispatch?
Find a dispatch record for a specific job and fire time.
48 49 50 |
# File 'lib/kaal/dispatch/database_engine.rb', line 48 def find_dispatch(key, fire_time) ::Kaal::CronDispatch.find_by(key: key, fire_time: fire_time) end |
#log_dispatch(key, fire_time, node_id, status = 'dispatched') ⇒ Kaal::CronDispatch
Log a dispatch attempt in the database.
32 33 34 35 36 37 38 39 40 |
# File 'lib/kaal/dispatch/database_engine.rb', line 32 def log_dispatch(key, fire_time, node_id, status = 'dispatched') ::Kaal::CronDispatch.create!( key: key, fire_time: fire_time, dispatched_at: Time.current, node_id: node_id, status: status ) end |