No supported way to cancel a job that is already executing!
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Look at the SolidQueue::ClaimedExecution class and its discard method that raises UndiscardableError. Understand how jobs are claimed and finalized. The goal is to design a way to signal cancellation to a running job, perhaps by adding a flag or a cooperative check, and to allow discard to work on executing jobs. Review the existing job lifecycle and the finalize method's logic.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
SolidQueue supports cancelling a queued (ready/scheduled) job cleanly via job.discard (as clarified in #395). But there is no supported way to cancel a job that is already executing (claimed) — ClaimedExecution#discard explicitly raises:
def discard
raise UndiscardableError, "Can't discard a job in progress"
end
In Quepid we have very long "LLM as a judge" type jobs taht could run for many many minutes or hours... And you might say "oh, crap, it's not what I want" and then it's awkward. We wrote a bunch of janky code to support this.
Current behavior
Applications that want a user-facing "Cancel" button for a long-running job (ours: an AI judging run scoped to one book+judge, potentially processing hundreds of records) have no sanctioned way to request cancellation of an already-claimed job. Our workaround bypasses the guard directly:
def self.cancel book, judge
active_for(book, judge).each do |job|
if job.claimed_execution.present?
# Job is actively running — force destroy it. The job's own #perform
# loop checks for its own SolidQueue row on every iteration and stops
# as soon as it notices this row is gone.
job.claimed_execution.destroy
job.destroy
else
job.discard
end
end
end
This only works because ClaimedExecution#finalize's unless_already_finalized check (self.class.unscoped.lock.find_by(id: id)) happens to tolerate the claimed_execution row already being gone by the time the job actually finishes — but that's an internal implementation detail we're relying on, not a documented contract, and it could change between versions without notice.
It also means the running job's #perform never gets any signal that cancellation was requested other than a self-written polling loop:
cancellable = SolidQueue::Job.exists?(active_job_id: job_id)
loop do
break if cancellable && !SolidQueue::Job.exists?(active_job_id: job_id)
# ... do one unit of work ...
end
There's no cooperative "cancellation requested" flag to check cheaply, and no built-in helper for this pattern either — every app doing cooperative cancellation re-derives the same polling idiom.
Why this belongs in SolidQueue, not application code
ClaimedExecution, #finalize, and the UndiscardableError guard are all internal to SolidQueue; there's no supported extension point for "cancel this specific already-running job" without reaching past that guard into internals that could change between versions.
Related
#395 covers cancelling a scheduled (not-yet-executing) job via discard — this issue is specifically about the claimed/executing case, which that thread doesn't touch.
- Ngôn ngữ chính
- Ruby
- Star
- 2.5k
- Fork
- 250
- Merge trung bình
- 8 giờ 31 phút
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rails/solid_queue
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
rails/solid_queue#805 ·
-
limits_concurrency on_conflict: :discard looking only into running jobs and not blocked jobs Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
rails/solid_queue#804 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
rails/solid_queue#802 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
rails/solid_queue#797 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
rails/solid_queue#792 · 1 reaction ·
Tất cả issue của rails/solid_queue
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
simp/pupmod-simp-simp#395 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-pupmod#256 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-sudo#150 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100