Skip to content

Commit 3f04e8f

Browse files
committed
Remove parent/child batch relationship, which simplifies the logic
1 parent 40773eb commit 3f04e8f

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

app/models/solid_queue/batch.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ module SolidQueue
44
class Batch < Record
55
include Trackable
66

7-
belongs_to :parent_batch, foreign_key: :parent_batch_id, primary_key: :batch_id, class_name: "SolidQueue::Batch", optional: true
87
has_many :jobs, foreign_key: :batch_id, primary_key: :batch_id
98
has_many :batch_executions, foreign_key: :batch_id, primary_key: :batch_id, class_name: "SolidQueue::BatchExecution"
10-
has_many :child_batches, foreign_key: :parent_batch_id, primary_key: :batch_id, class_name: "SolidQueue::Batch"
119

1210
serialize :on_finish, coder: JSON
1311
serialize :on_success, coder: JSON
1412
serialize :on_failure, coder: JSON
1513
serialize :metadata, coder: JSON
1614

1715
after_initialize :set_batch_id
18-
before_create :set_parent_batch_id
1916
after_commit :start_batch, on: :create, unless: -> { ActiveRecord.respond_to?(:after_all_transactions_commit) }
2017

2118
mattr_accessor :maintenance_queue_name
@@ -68,10 +65,6 @@ def check_completion!
6865

6966
private
7067

71-
def set_parent_batch_id
72-
self.parent_batch_id ||= Batch.current_batch_id if Batch.current_batch_id.present?
73-
end
74-
7568
def set_batch_id
7669
self.batch_id ||= SecureRandom.uuid
7770
end
@@ -132,8 +125,7 @@ def enqueue(on_success: nil, on_failure: nil, on_finish: nil, metadata: nil, &bl
132125
on_success: on_success,
133126
on_failure: on_failure,
134127
on_finish: on_finish,
135-
metadata: metadata,
136-
parent_batch_id: current_batch_id
128+
metadata: metadata
137129
)
138130

139131
batch.enqueue(&block)

lib/generators/solid_queue/install/templates/db/queue_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124

125125
create_table "solid_queue_batches", force: :cascade do |t|
126126
t.string "batch_id"
127-
t.string "parent_batch_id"
128127
t.text "on_finish"
129128
t.text "on_success"
130129
t.text "on_failure"
@@ -139,14 +138,14 @@
139138
t.datetime "created_at", null: false
140139
t.datetime "updated_at", null: false
141140
t.index ["batch_id"], name: "index_solid_queue_batches_on_batch_id", unique: true
142-
t.index ["parent_batch_id"], name: "index_solid_queue_batches_on_parent_batch_id"
143141
end
144142

145143
create_table "solid_queue_batch_executions", force: :cascade do |t|
146144
t.bigint "job_id", null: false
147145
t.string "batch_id", null: false
148146
t.datetime "created_at", null: false
149147
t.index [ "job_id" ], name: "index_solid_queue_batch_executions_on_job_id", unique: true
148+
t.index ["batch_id"], name: "index_solid_queue_batch_executions_on_batch_id"
150149
end
151150

152151
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade

test/dummy/db/queue_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136

137137
create_table "solid_queue_batches", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
138138
t.string "batch_id"
139-
t.string "parent_batch_id"
140139
t.text "on_finish"
141140
t.text "on_success"
142141
t.text "on_failure"
@@ -151,14 +150,14 @@
151150
t.datetime "created_at", null: false
152151
t.datetime "updated_at", null: false
153152
t.index ["batch_id"], name: "index_solid_queue_batches_on_batch_id", unique: true
154-
t.index ["parent_batch_id"], name: "index_solid_queue_batches_on_parent_batch_id"
155153
end
156154

157155
create_table "solid_queue_batch_executions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
158156
t.bigint "job_id", null: false
159157
t.string "batch_id", null: false
160158
t.datetime "created_at", null: false
161159
t.index ["job_id"], name: "index_solid_queue_batch_executions_on_job_id", unique: true
160+
t.index ["batch_id"], name: "index_solid_queue_batch_executions_on_batch_id"
162161
end
163162

164163
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade

0 commit comments

Comments
 (0)