Class: Kaal::Backend::Adapter
- Inherits:
-
Object
- Object
- Kaal::Backend::Adapter
- Defined in:
- lib/kaal/backend/adapter.rb
Overview
Abstract base class for distributed backend adapters.
Backend adapters are responsible for distributed coordination (acquire/release) and may also expose cron definition and dispatch registries for persistence.
Direct Known Subclasses
MemoryAdapter, MySQL, NullAdapter, Postgres, RedisAdapter, SQLite, Internal::ActiveRecord::DatabaseBackend, Internal::ActiveRecord::MySQLBackend, Internal::ActiveRecord::PostgresBackend, Internal::Sequel::DatabaseBackend, Internal::Sequel::MySQLBackend, Internal::Sequel::PostgresBackend
Instance Method Summary collapse
-
#acquire(_key, _ttl) ⇒ Boolean
Attempt to acquire a distributed lock.
-
#definition_registry ⇒ Kaal::Definition::Registry?
Optional definition registry for persistent cron definitions.
- #delayed_store ⇒ Object
-
#release(_key) ⇒ Boolean
Release a previously acquired lock.
-
#with_lock(key, ttl:) { ... } ⇒ Object
Acquire a lock, execute the block, then release the lock.
Instance Method Details
#acquire(_key, _ttl) ⇒ Boolean
Attempt to acquire a distributed lock.
42 43 44 |
# File 'lib/kaal/backend/adapter.rb', line 42 def acquire(_key, _ttl) raise NotImplementedError, 'Subclasses must implement #acquire' end |
#definition_registry ⇒ Kaal::Definition::Registry?
Optional definition registry for persistent cron definitions.
Backends may override this to provide a concrete implementation.
94 95 96 |
# File 'lib/kaal/backend/adapter.rb', line 94 def definition_registry nil end |
#delayed_store ⇒ Object
98 99 100 |
# File 'lib/kaal/backend/adapter.rb', line 98 def delayed_store nil end |
#release(_key) ⇒ Boolean
Release a previously acquired lock.
56 57 58 |
# File 'lib/kaal/backend/adapter.rb', line 56 def release(_key) raise NotImplementedError, 'Subclasses must implement #release' end |
#with_lock(key, ttl:) { ... } ⇒ Object
Acquire a lock, execute the block, then release the lock.
This is a convenience method that ensures the lock is properly released even if the block raises an exception. If the lock cannot be acquired, returns nil without executing the block.
78 79 80 81 82 83 84 85 86 |
# File 'lib/kaal/backend/adapter.rb', line 78 def with_lock(key, ttl:) return nil unless acquire(key, ttl) begin yield ensure release(key) end end |