Proposal: deduplicate pending jobs with coalesce
維護者通常 4 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Read the original uniqueness discussion (#105), concurrency discussions (#176 and #597), and exploratory PR #835 alongside the solid_queue-coalesce reference gem. Start by evaluating whether the proposed pending-job lifecycle and API fit Solid Queue's enqueue, dispatch, and cleanup paths. Done means maintainers agree on whether the feature belongs in core and, if so, define its minimal API and persistence model.
由索引模型根據 Issue 內容生成。
描述
Hi Rosa and team,
David (human) here. We've used Solid Queue in production for nearly a year and love it.
We found that limits_concurrency on_conflict: :discard doesn't deduplicate scheduled jobs. After causing us a production incident, we also discovered that it can discard important work on a retry. I feel that limits_concurrency is not the right tool for deduplication.
Below is my AI-authored issue that describes the problem and my proposed solution, introducing the concept I'm calling coalesce.
I've written a gem solid_queue-coalesce (that composes well with limits_concurrency) exploring these ideas further, including replacing arguments, collecting calls into batches, debouncing and throttling. For now, I'm only proposing basic deduplication, but check out the gem if you're curious about the rest.
Motivation
Issue #105 described one pending job per key, with another allowed as soon as the first starts. limits_concurrency on_conflict: :discard (#176, #594) controls execution, not pending jobs:
- Scheduled jobs can accumulate, and more than one can run (#597).
- Calls made during execution can be dropped, even if the running job has already read the state being updated.
- Callers can't identify which existing job covers their request.
For example, repeated product changes should share one pending reindex. A change during that reindex should schedule the next one.
on_conflict: :discard remains useful for shedding load; coalescing would complement it.
Proposal
class ReindexProductJob < ApplicationJob
coalesce key: ->(product_id) { product_id }
def perform(product_id)
Product.find(product_id).reindex!
end
end
- Calls with the same key, including scheduled ones, share one pending job.
- The key is released when that job starts, so a call during execution queues the next one.
- Keys are scoped to the job class and batch; retries never coalesce.
coalesce_status(:createdor:discarded) andprovider_job_idtell the caller what happened.- Semaphores from
limits_concurrencyare untouched.
The first job's arguments and scheduled time are retained. Collecting calls, replacing arguments and debouncing are outside this proposal.
Implementation
The standalone gem works but patches private Solid Queue methods, making upgrades fragile. Native support could avoid that. #835 illustrates a minimal implementation using a solid_queue_coalesce_keys table and row locks; it's intended to support discussion, not represent a complete solution. The gem also has benchmarks.
Trade-offs
- A new table requires a migration.
- Row locking introduces contention and potential deadlocks; #835 also enqueues coalesced bulk jobs individually, allowing partial batches on failure.
- Two jobs with the same key can run at once. Add
limits_concurrencyto prevent that.
Questions
- Would you want pending-job coalescing in Solid Queue?
- Should it be its own
coalesce key:declaration, or an option onlimits_concurrency? - If it stays a gem, would you take small public extension points so it doesn't have to patch private methods?
🤖 Written by @dtcristo's agent (Claude Opus 5.5)
- 主要語言
- Ruby
- 星號
- 2.5k
- 分支
- 271
- 平均合併
- 5 天 6 小時
- 30 天內合併 PR
- 5
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rails/solid_queue 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
rails/solid_queue#838 ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 45/100
rails/solid_queue#836 ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
rails/solid_queue#824 · 1 個 reaction ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 42/100
rails/solid_queue#808 · 3 則留言 ·
維護者通常 4 天內回覆
-
難度 4/5 3-5 天 新手友好度 45/100
rails/solid_queue#806 ·
維護者通常 4 天內回覆
查看 rails/solid_queue 的全部 Issue
相似的 Issue
-
開発用DockerイメージにPlaywrightのシステム依存を追加する可能已有人在做 @momocus 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 85/100
sakazuki-org/sakazuki#1453 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
jenkins-infra/jenkins.io#9615 · 1 則留言 ·
維護者通常 1 天內回覆
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtime可能已有人在做 @Goldziher 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Metric tooltips that contradict how the metric is calculated可能已有人在做 @aniadeadu 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
WikiEducationFoundation/WikiEduDashboard#7303 · 1 則留言 ·
維護者通常 1 天內回覆
-
WhatsApp Cloud template sync saves a partial template list when one page of the Graph API response fails可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 2 天內回覆