Skip to content

Commit e93e23d

Browse files
committed
Don't try to release claimed executions for dispatchers and supervisors
1 parent 530a50b commit e93e23d

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

app/models/solid_queue/process.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# frozen_string_literal: true
22

33
class SolidQueue::Process < SolidQueue::Record
4-
include Prunable
4+
include Executor, Prunable
55

66
belongs_to :supervisor, class_name: "SolidQueue::Process", optional: true, inverse_of: :supervisees
77
has_many :supervisees, class_name: "SolidQueue::Process", inverse_of: :supervisor, foreign_key: :supervisor_id, dependent: :destroy
8-
has_many :claimed_executions
98

109
store :metadata, coder: JSON
1110

12-
after_destroy -> { claimed_executions.release_all }
13-
1411
def self.register(**attributes)
1512
SolidQueue.instrument :register_process, **attributes do |payload|
1613
create!(attributes.merge(last_heartbeat_at: Time.current)).tap do |process|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module SolidQueue
4+
class Process
5+
module Executor
6+
extend ActiveSupport::Concern
7+
8+
included do
9+
has_many :claimed_executions
10+
11+
after_destroy -> { claimed_executions.release_all }, if: :claims_executions?
12+
end
13+
14+
private
15+
def claims_executions?
16+
kind == "Worker"
17+
end
18+
end
19+
end
20+
end

app/models/solid_queue/process/prunable.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# frozen_string_literal: true
22

3-
module SolidQueue::Process::Prunable
4-
extend ActiveSupport::Concern
3+
module SolidQueue
4+
class Process
5+
module Prunable
6+
extend ActiveSupport::Concern
57

6-
included do
7-
scope :prunable, -> { where(last_heartbeat_at: ..SolidQueue.process_alive_threshold.ago) }
8-
end
8+
included do
9+
scope :prunable, -> { where(last_heartbeat_at: ..SolidQueue.process_alive_threshold.ago) }
10+
end
911

10-
class_methods do
11-
def prune
12-
SolidQueue.instrument :prune_processes, size: 0 do |payload|
13-
prunable.non_blocking_lock.find_in_batches(batch_size: 50) do |batch|
14-
payload[:size] += batch.size
12+
class_methods do
13+
def prune
14+
SolidQueue.instrument :prune_processes, size: 0 do |payload|
15+
prunable.non_blocking_lock.find_in_batches(batch_size: 50) do |batch|
16+
payload[:size] += batch.size
1517

16-
batch.each { |process| process.deregister(pruned: true) }
18+
batch.each { |process| process.deregister(pruned: true) }
19+
end
20+
end
1721
end
1822
end
1923
end

0 commit comments

Comments
 (0)