codesnips
Browse Tags Share a snippet
Sign in
Join us today
Share your craft projects Make new craft buddies Ask craft questions Blog your craft journey
All Latest Trending
ruby
module AdvisoryLock
  module_function

  def with_lock(key)
    lock_id = Zlib.crc32(key.to_s)
    got_lock = ApplicationRecord.connection.select_value("SELECT pg_try_advisory_lock(#{lock_id})")

Idempotent Job with Advisory Lock

rails activejob postgres
by Sarah Chen 2 tabs
ruby
class OutboxEvent < ApplicationRecord
  enum status: { pending: 0, publishing: 1, published: 2, failed: 3 }

  validates :event_name, :aggregate_type, :aggregate_id, presence: true
  validates :dedupe_key, presence: true, uniqueness: true

Transactional Outbox for Reliable Event Publishing

rails activerecord background-jobs
by Sarah Chen 3 tabs
Previous
1 ... 87 88 89
Next
CodeSnips

CodeSnips is crafted with passion and great attention to detail.

Privacy Terms
Facebook Instagram Pinterest
Tags

© 2024 CodeSnips. All Rights Reserved. Running on Ruby on Rails.

Disclaimer: Any posts on CodeSnips.io are posted by individuals acting in their own right and do not necessarily reflect the views of CodeSnips.
CodeSnips will not be held liable for the actions of any user.