Proposal: deduplicate pending jobs with coalesce
Maintainer antworten meist innerhalb von 4 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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)
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.5k
- Forks
- 271
- Ø Merge
- 5 T. 6 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rails/solid_queue
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
rails/solid_queue#838 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 45/100
rails/solid_queue#836 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
rails/solid_queue#824 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 42/100
rails/solid_queue#808 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
rails/solid_queue#806 ·
Maintainer antworten meist innerhalb von 4 Tagen
Alle Issues in rails/solid_queue
Ähnliche Issues
-
開発用DockerイメージにPlaywrightのシステム依存を追加するEvtl. vergeben @momocus hat das heute übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
sakazuki-org/sakazuki#1453 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
jenkins-infra/jenkins.io#9615 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtimeEvtl. vergeben @Goldziher hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Metric tooltips that contradict how the metric is calculatedEvtl. vergeben @aniadeadu hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
WikiEducationFoundation/WikiEduDashboard#7303 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
WhatsApp Cloud template sync saves a partial template list when one page of the Graph API response failsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 2 Tagen