Suggested API: on_conflict: :replace

オープン
#824 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
rails, ruby
領域
backend, database

調査の方向性

The payload names no files or tests. Start from the existing on_conflict: :discard path used by limits_concurrency, then trace how a pending job is stored and identified by its concurrency key. Decide the semantics for :replace and whether payload batching is included, then add coverage for first-wins versus last-wins behavior. Done means the new option is implemented, documented, and tested for duplicate enqueues while a matching job is still waiting.

索引モデルが issue の本文から書いたものです。

説明

Description

Currently, Solid Queue provides an on_conflict: :discard option to enforce uniqueness. This follows a "first wins" behavior, where subsequent duplicate jobs are dropped if a matching job is already pending in the queue.

However, many use cases (such as syncing the latest user state or syncing inventory) require a "last value wins" strategy. If a new job with the exact same concurrency key is enqueued while a previous one is still waiting, the queue should ensure that only the latest job (carrying the freshest payload) is processed. This can be achieved either by replacing the pending job entirely or updating its payload.

Introducing this strategy would also significantly boost performance under high-frequency updates, as it prevents the system from wasting database and worker cycles processing outdated intermediate payloads.

Examples from other queue managers

• Sidekiq Enterprise / Sidekiq Unique Jobs: Supports options like on_conflict: :replace or rescheduling to overwrite the payload of an un-executed job with the freshest data.
• Lowkiq: Passes an array of all enqueued payloads directly to the perform method, allowing the developer to decide how to process or batch them.

Suggested API

It would be useful to introduce a configuration option to define how concurrency conflicts are handled:
Option A: Pure :replace strategy

class UpdateInventoryJob < ApplicationJob
  limits_concurrency to: 1, key: ->(payload) { payload.id }, on_conflict: :replace

  def perform(payload)
    # ...
  end
end

Option B: Custom conflict hook with payload batching

class UpdateInventoryJob < ApplicationJob
  limits_concurrency to: 1, key: ->(product) { product.id }, on_conflict: :replace

  def perform_on_conflict(payloads)
    # Allows manually processing the final state
    perform(payloads.last)
  end
end
主要言語
Ruby
スター
2.5k
フォーク
271
平均マージ
5日 6時間
マージ済み PR(30日)
5

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rails/solid_queue のほかの issue

rails/solid_queue の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。