Class: Webhookdb::Idempotency::InDatabase
- Inherits:
-
Object
- Object
- Webhookdb::Idempotency::InDatabase
- Defined in:
- lib/webhookdb/idempotency.rb
Instance Method Summary collapse
- #db ⇒ Object
- #ensure(key) ⇒ Object
- #finish(key, last_run:, stored:, result:) ⇒ Object
-
#initialize(conn) ⇒ InDatabase
constructor
A new instance of InDatabase.
- #lock(key) ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(conn) ⇒ InDatabase
Returns a new instance of InDatabase.
169 170 171 |
# File 'lib/webhookdb/idempotency.rb', line 169 def initialize(conn) @conn = conn end |
Instance Method Details
#db ⇒ Object
173 |
# File 'lib/webhookdb/idempotency.rb', line 173 def db = @conn |
#ensure(key) ⇒ Object
175 |
# File 'lib/webhookdb/idempotency.rb', line 175 def ensure(key) = db[:idempotencies].insert_conflict.insert(key:) |
#finish(key, last_run:, stored:, result:) ⇒ Object
178 179 180 181 182 |
# File 'lib/webhookdb/idempotency.rb', line 178 def finish(key, last_run:, stored:, result:) updates = {last_run:} updates[:stored_result] = Sequel.pg_jsonb_wrap(result) if stored db[:idempotencies].where(key:).update(updates) end |
#lock(key) ⇒ Object
176 |
# File 'lib/webhookdb/idempotency.rb', line 176 def lock(key) = db[:idempotencies].where(key:).for_update.first |
#transaction ⇒ Object
174 |
# File 'lib/webhookdb/idempotency.rb', line 174 def transaction(&) = db.transaction(&) |