Class: Webhookdb::Idempotency::InDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/idempotency.rb

Instance Method Summary collapse

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

#dbObject



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

#transactionObject



174
# File 'lib/webhookdb/idempotency.rb', line 174

def transaction(&) = db.transaction(&)