switchman-inst-jobs 3.2.10 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20101216224513_create_delayed_jobs.rb +1 -1
- data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +1 -1
- data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +1 -1
- data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +1 -1
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +1 -1
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +1 -1
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +1 -1
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +1 -1
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -1
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +1 -1
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -2
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
- data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +1 -1
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -2
- data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +1 -1
- data/db/migrate/20140512213941_add_source_to_jobs.rb +1 -1
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +1 -1
- data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +1 -1
- data/db/migrate/20151210162949_improve_max_concurrent.rb +1 -1
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +1 -1
- data/db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb +1 -11
- data/db/migrate/20170308045401_add_delayed_jobs_shard_id_to_switchman_shards.rb +5 -0
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +1 -1
- data/db/migrate/20190726154743_make_critical_columns_not_null.rb +1 -1
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -2
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +1 -1
- data/db/migrate/20200825011002_add_strand_order_override.rb +2 -2
- data/lib/switchman_inst_jobs/active_record/connection_adapters/connection_pool.rb +15 -0
- data/lib/switchman_inst_jobs/delayed/backend/base.rb +9 -8
- data/lib/switchman_inst_jobs/delayed/pool.rb +1 -1
- data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +10 -12
- data/lib/switchman_inst_jobs/delayed/worker.rb +2 -2
- data/lib/switchman_inst_jobs/engine.rb +8 -10
- data/lib/switchman_inst_jobs/jobs_migrator.rb +91 -145
- data/lib/switchman_inst_jobs/switchman/shard.rb +8 -21
- data/lib/switchman_inst_jobs/version.rb +1 -1
- data/lib/switchman_inst_jobs.rb +4 -0
- metadata +58 -28
- data/db/migrate/20211220112800_fix_singleton_race_condition_insert.rb +0 -59
- data/db/migrate/20211220113000_fix_singleton_race_condition_delete.rb +0 -207
- data/db/migrate/20220127091200_fix_singleton_unique_constraint.rb +0 -31
- data/db/migrate/20220128084800_update_insert_trigger_for_singleton_unique_constraint_change.rb +0 -60
- data/db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb +0 -209
- data/db/migrate/20220203063200_remove_old_singleton_index.rb +0 -31
@@ -13,10 +13,10 @@ module SwitchmanInstJobs
|
|
13
13
|
return yield if shards.empty?
|
14
14
|
|
15
15
|
shard = shards.pop
|
16
|
-
current_shard = ::Switchman::Shard.current(
|
17
|
-
shard.activate(
|
16
|
+
current_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
17
|
+
shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
18
18
|
::Delayed::Job.transaction do
|
19
|
-
current_shard.activate(
|
19
|
+
current_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
20
20
|
transaction_on(shards, &block)
|
21
21
|
end
|
22
22
|
end
|
@@ -45,11 +45,11 @@ module SwitchmanInstJobs
|
|
45
45
|
# rubocop:disable Style/CombinableLoops
|
46
46
|
# We first migrate strands so that we can stop blocking strands before we migrate unstranded jobs
|
47
47
|
source_shards.each do |s|
|
48
|
-
::Switchman::Shard.lookup(s).activate(
|
48
|
+
::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_strands }
|
49
49
|
end
|
50
50
|
|
51
51
|
source_shards.each do |s|
|
52
|
-
::Switchman::Shard.lookup(s).activate(
|
52
|
+
::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_everything }
|
53
53
|
end
|
54
54
|
ensure_unblock_stranded_for(shard_map.map(&:first))
|
55
55
|
# rubocop:enable Style/CombinableLoops
|
@@ -72,7 +72,7 @@ module SwitchmanInstJobs
|
|
72
72
|
|
73
73
|
def clear_shard_cache(debug_message = nil)
|
74
74
|
::Switchman.cache.clear
|
75
|
-
Rails.logger.debug
|
75
|
+
Rails.logger.debug { "Waiting for caches to clear #{debug_message}" }
|
76
76
|
# Wait a little over the 60 second in-process shard cache clearing
|
77
77
|
# threshold to ensure that all new stranded jobs are now being
|
78
78
|
# enqueued with next_in_strand: false
|
@@ -89,9 +89,7 @@ module SwitchmanInstJobs
|
|
89
89
|
migrate_everything
|
90
90
|
end
|
91
91
|
|
92
|
-
def migrate_strands
|
93
|
-
source_shard = ::Switchman::Shard.current(:delayed_jobs)
|
94
|
-
|
92
|
+
def migrate_strands
|
95
93
|
# there are 4 scenarios to deal with here
|
96
94
|
# 1) no running job, no jobs moved: do nothing
|
97
95
|
# 2) running job, no jobs moved; create blocker with next_in_strand=false
|
@@ -100,89 +98,60 @@ module SwitchmanInstJobs
|
|
100
98
|
# those (= do nothing since it should already be false)
|
101
99
|
# 4) no running job, jobs moved: set next_in_strand=true on the first of
|
102
100
|
# those (= do nothing since it should already be true)
|
103
|
-
handler = lambda { |scope, column, blocker_job_kwargs = {}, advisory_lock_cb = nil|
|
104
|
-
shard_map = build_shard_map(scope, source_shard)
|
105
|
-
shard_map.each do |(target_shard, source_shard_ids)|
|
106
|
-
shard_scope = scope.where(shard_id: source_shard_ids)
|
107
|
-
|
108
|
-
# 1) is taken care of because it should not show up here in strands
|
109
|
-
values = shard_scope.distinct.order(column).pluck(column)
|
110
|
-
|
111
|
-
target_shard.activate(:delayed_jobs) do
|
112
|
-
values.each do |value|
|
113
|
-
transaction_on([source_shard, target_shard]) do
|
114
|
-
source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
115
|
-
advisory_lock_cb&.call(value)
|
116
|
-
end
|
117
|
-
|
118
|
-
value_scope = shard_scope.where(**{ column => value })
|
119
|
-
# we want to copy all the jobs except the one that is still running.
|
120
|
-
jobs_scope = value_scope.where(locked_by: nil)
|
121
|
-
|
122
|
-
# 2) and part of 3) are taken care of here by creating a blocker
|
123
|
-
# job with next_in_strand = false. as soon as the current
|
124
|
-
# running job is finished it should set next_in_strand
|
125
|
-
# We lock it to ensure that the jobs worker can't delete it until we are done moving the strand
|
126
|
-
# Since we only unlock it on the new jobs queue *after* deleting from the original
|
127
|
-
# the lock ensures the blocker always gets unlocked
|
128
|
-
first = value_scope.where.not(locked_by: nil).next_in_strand_order.lock.first
|
129
|
-
if first
|
130
|
-
create_blocker_job(
|
131
|
-
queue: first.queue,
|
132
|
-
shard_id: first.shard_id,
|
133
|
-
**{ column => value },
|
134
|
-
**blocker_job_kwargs
|
135
|
-
)
|
136
|
-
|
137
|
-
# the rest of 3) is taken care of here
|
138
|
-
# make sure that all the jobs moved over are NOT next in strand
|
139
|
-
::Delayed::Job.where(next_in_strand: true, locked_by: nil, **{ column => value }).
|
140
|
-
update_all(next_in_strand: false)
|
141
|
-
end
|
142
|
-
|
143
|
-
# 4) is taken care of here, by leaving next_in_strand alone and
|
144
|
-
# it should execute on the new shard
|
145
|
-
batch_move_jobs(
|
146
|
-
target_shard: target_shard,
|
147
|
-
source_shard: source_shard,
|
148
|
-
scope: jobs_scope,
|
149
|
-
batch_size: batch_size
|
150
|
-
) do |job, new_job|
|
151
|
-
# This ensures jobs enqueued on the old jobs shard run before jobs on the new jobs queue
|
152
|
-
new_job.strand_order_override = job.strand_order_override - 1
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
}
|
159
101
|
|
102
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
160
103
|
strand_scope = ::Delayed::Job.shard(source_shard).where.not(strand: nil)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
104
|
+
shard_map = build_shard_map(strand_scope, source_shard)
|
105
|
+
shard_map.each do |(target_shard, source_shard_ids)|
|
106
|
+
shard_scope = strand_scope.where(shard_id: source_shard_ids)
|
107
|
+
|
108
|
+
# 1) is taken care of because it should not show up here in strands
|
109
|
+
strands = shard_scope.distinct.order(:strand).pluck(:strand)
|
110
|
+
|
111
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
112
|
+
strands.each do |strand|
|
113
|
+
transaction_on([source_shard, target_shard]) do
|
114
|
+
this_strand_scope = shard_scope.where(strand: strand)
|
115
|
+
# we want to copy all the jobs except the one that is still running.
|
116
|
+
jobs_scope = this_strand_scope.where(locked_by: nil)
|
117
|
+
|
118
|
+
# 2) and part of 3) are taken care of here by creating a blocker
|
119
|
+
# job with next_in_strand = false. as soon as the current
|
120
|
+
# running job is finished it should set next_in_strand
|
121
|
+
# We lock it to ensure that the jobs worker can't delete it until we are done moving the strand
|
122
|
+
# Since we only unlock it on the new jobs queue *after* deleting from the original
|
123
|
+
# the lock ensures the blocker always gets unlocked
|
124
|
+
first = this_strand_scope.where.not(locked_by: nil).next_in_strand_order.lock.first
|
125
|
+
if first
|
126
|
+
first_job = ::Delayed::Job.create!(strand: strand, next_in_strand: false)
|
127
|
+
first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, args: [0])
|
128
|
+
first_job.queue = first.queue
|
129
|
+
first_job.tag = 'Kernel.sleep'
|
130
|
+
first_job.source = 'JobsMigrator::StrandBlocker'
|
131
|
+
first_job.max_attempts = 1
|
132
|
+
# If we ever have jobs left over from 9999 jobs moves of a single shard,
|
133
|
+
# something has gone terribly wrong
|
134
|
+
first_job.strand_order_override = -9999
|
135
|
+
first_job.save!
|
136
|
+
# the rest of 3) is taken care of here
|
137
|
+
# make sure that all the jobs moved over are NOT next in strand
|
138
|
+
::Delayed::Job.where(next_in_strand: true, strand: strand, locked_by: nil).
|
139
|
+
update_all(next_in_strand: false)
|
140
|
+
end
|
179
141
|
|
180
|
-
|
181
|
-
|
142
|
+
# 4) is taken care of here, by leaving next_in_strand alone and
|
143
|
+
# it should execute on the new shard
|
144
|
+
batch_move_jobs(
|
145
|
+
target_shard: target_shard,
|
146
|
+
source_shard: source_shard,
|
147
|
+
scope: jobs_scope
|
148
|
+
) do |job, new_job|
|
149
|
+
# This ensures jobs enqueued on the old jobs shard run before jobs on the new jobs queue
|
150
|
+
new_job.strand_order_override = job.strand_order_override - 1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
182
154
|
|
183
|
-
shard_map = build_shard_map(all_scope, source_shard)
|
184
|
-
shard_map.each do |(target_shard, source_shard_ids)|
|
185
|
-
target_shard.activate(:delayed_jobs) do
|
186
155
|
updated = ::Switchman::Shard.where(id: source_shard_ids, block_stranded: true).
|
187
156
|
update_all(block_stranded: false)
|
188
157
|
# If this is being manually re-run for some reason to clean something up, don't wait for nothing to happen
|
@@ -197,68 +166,41 @@ module SwitchmanInstJobs
|
|
197
166
|
end
|
198
167
|
end
|
199
168
|
|
200
|
-
def unblock_strands(target_shard
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
169
|
+
def unblock_strands(target_shard)
|
170
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
171
|
+
loop do
|
172
|
+
# We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
|
173
|
+
# to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
|
174
|
+
# this target shard, so we shouldn't unlock them yet. We only ever unlock one job here to keep the
|
175
|
+
# logic cleaner; if the job is n-stranded, after the first one runs, the trigger will unlock larger
|
176
|
+
# batches
|
177
|
+
break if ::Delayed::Job.where(id: ::Delayed::Job.select('DISTINCT ON (strand) id').
|
178
|
+
where.not(strand: nil).
|
179
|
+
where.not(shard_id: ::Switchman::Shard.where(block_stranded: true).pluck(:id)).where(
|
208
180
|
::Delayed::Job.select(1).from("#{::Delayed::Job.quoted_table_name} dj2").
|
209
181
|
where("dj2.next_in_strand = true OR dj2.source = 'JobsMigrator::StrandBlocker'").
|
210
|
-
where(
|
211
|
-
).
|
212
|
-
order(column, :strand_order_override, :id)).limit(batch_size)
|
213
|
-
}
|
214
|
-
|
215
|
-
target_shard.activate(:delayed_jobs) do
|
216
|
-
# We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
|
217
|
-
# to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
|
218
|
-
# this target shard, so we shouldn't unlock them yet. We only ever unlock one job here to keep the
|
219
|
-
# logic cleaner; if the job is n-stranded, after the first one runs, the trigger will unlock larger
|
220
|
-
# batches
|
221
|
-
|
222
|
-
loop do
|
223
|
-
break if query.call(:strand, 'strand IS NOT NULL').update_all(next_in_strand: true).zero?
|
224
|
-
end
|
225
|
-
|
226
|
-
loop do
|
227
|
-
break if query.call(:singleton,
|
228
|
-
'strand IS NULL AND singleton IS NOT NULL').update_all(next_in_strand: true).zero?
|
182
|
+
where('dj2.strand = delayed_jobs.strand').arel.exists.not
|
183
|
+
).order(:strand, :strand_order_override, :id)).limit(500).update_all(next_in_strand: true).zero?
|
229
184
|
end
|
230
185
|
end
|
231
186
|
end
|
232
187
|
|
233
|
-
def migrate_everything
|
234
|
-
source_shard = ::Switchman::Shard.current(
|
235
|
-
scope = ::Delayed::Job.shard(source_shard).where(
|
188
|
+
def migrate_everything
|
189
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
190
|
+
scope = ::Delayed::Job.shard(source_shard).where(strand: nil)
|
236
191
|
|
237
192
|
shard_map = build_shard_map(scope, source_shard)
|
238
193
|
shard_map.each do |(target_shard, source_shard_ids)|
|
239
194
|
batch_move_jobs(
|
240
195
|
target_shard: target_shard,
|
241
196
|
source_shard: source_shard,
|
242
|
-
scope: scope.where(shard_id: source_shard_ids).where(locked_by: nil)
|
243
|
-
batch_size: batch_size
|
197
|
+
scope: scope.where(shard_id: source_shard_ids).where(locked_by: nil)
|
244
198
|
)
|
245
199
|
end
|
246
200
|
end
|
247
201
|
|
248
202
|
private
|
249
203
|
|
250
|
-
def create_blocker_job(**kwargs)
|
251
|
-
first_job = ::Delayed::Job.create!(**kwargs, next_in_strand: false)
|
252
|
-
first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, args: [0])
|
253
|
-
first_job.tag = 'Kernel.sleep'
|
254
|
-
first_job.source = 'JobsMigrator::StrandBlocker'
|
255
|
-
first_job.max_attempts = 1
|
256
|
-
# If we ever have jobs left over from 9999 jobs moves of a single shard,
|
257
|
-
# something has gone terribly wrong
|
258
|
-
first_job.strand_order_override = -9999
|
259
|
-
first_job.save!
|
260
|
-
end
|
261
|
-
|
262
204
|
def build_shard_map(scope, source_shard)
|
263
205
|
shard_ids = scope.distinct.pluck(:shard_id)
|
264
206
|
|
@@ -273,21 +215,25 @@ module SwitchmanInstJobs
|
|
273
215
|
shard_map
|
274
216
|
end
|
275
217
|
|
276
|
-
def batch_move_jobs(target_shard:, source_shard:, scope
|
218
|
+
def batch_move_jobs(target_shard:, source_shard:, scope:)
|
277
219
|
while scope.exists?
|
278
220
|
# Adapted from get_and_lock_next_available in delayed/backend/active_record.rb
|
279
|
-
target_jobs = scope.limit(
|
280
|
-
|
281
|
-
query = source_shard.activate(
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
221
|
+
target_jobs = scope.limit(1000).lock('FOR UPDATE SKIP LOCKED')
|
222
|
+
|
223
|
+
query = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
224
|
+
<<~SQL
|
225
|
+
WITH limited_jobs AS (#{target_jobs.to_sql})
|
226
|
+
UPDATE #{::Delayed::Job.quoted_table_name}
|
227
|
+
SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)},
|
228
|
+
locked_at = #{::Delayed::Job.connection.quote(::Delayed::Job.db_time_now)}
|
229
|
+
FROM limited_jobs WHERE limited_jobs.id=#{::Delayed::Job.quoted_table_name}.id
|
230
|
+
RETURNING #{::Delayed::Job.quoted_table_name}.*
|
231
|
+
SQL
|
288
232
|
end
|
289
233
|
|
290
|
-
jobs = source_shard.activate(
|
234
|
+
jobs = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
235
|
+
::Delayed::Job.find_by_sql(query)
|
236
|
+
end
|
291
237
|
new_jobs = jobs.map do |job|
|
292
238
|
new_job = job.dup
|
293
239
|
new_job.shard = target_shard
|
@@ -305,10 +251,10 @@ module SwitchmanInstJobs
|
|
305
251
|
new_job
|
306
252
|
end
|
307
253
|
transaction_on([source_shard, target_shard]) do
|
308
|
-
target_shard.activate(
|
254
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
309
255
|
bulk_insert_jobs(new_jobs)
|
310
256
|
end
|
311
|
-
source_shard.activate(
|
257
|
+
source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
312
258
|
::Delayed::Job.delete(jobs)
|
313
259
|
end
|
314
260
|
end
|
@@ -22,12 +22,12 @@ module SwitchmanInstJobs
|
|
22
22
|
def hold_jobs!(wait: false)
|
23
23
|
self.jobs_held = true
|
24
24
|
save! if changed?
|
25
|
-
delayed_jobs_shard.activate(
|
25
|
+
delayed_jobs_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
26
26
|
lock_jobs_for_hold
|
27
27
|
end
|
28
28
|
return unless wait
|
29
29
|
|
30
|
-
delayed_jobs_shard.activate(
|
30
|
+
delayed_jobs_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
31
31
|
while ::Delayed::Job.where(shard_id: id).
|
32
32
|
where.not(locked_at: nil).
|
33
33
|
where.not(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY).exists?
|
@@ -47,7 +47,7 @@ module SwitchmanInstJobs
|
|
47
47
|
Rails.logger.debug('Waiting for caches to clear')
|
48
48
|
sleep(65)
|
49
49
|
end
|
50
|
-
delayed_jobs_shard.activate(
|
50
|
+
delayed_jobs_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
51
51
|
::Delayed::Job.where(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY, shard_id: id).
|
52
52
|
in_batches(of: 10_000).
|
53
53
|
update_all(
|
@@ -75,22 +75,14 @@ module SwitchmanInstJobs
|
|
75
75
|
remove_instance_variable(:@delayed_jobs_shards) if instance_variable_defined?(:@delayed_jobs_shards)
|
76
76
|
end
|
77
77
|
|
78
|
-
def current(category = :primary)
|
79
|
-
if category == :delayed_jobs
|
80
|
-
active_shards[category] || super(:primary).delayed_jobs_shard
|
81
|
-
else
|
82
|
-
super
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
78
|
def activate!(categories)
|
87
79
|
if !@skip_delayed_job_auto_activation &&
|
88
|
-
!categories[
|
89
|
-
categories[
|
90
|
-
categories[
|
80
|
+
!categories[::Delayed::Backend::ActiveRecord::AbstractJob] &&
|
81
|
+
categories[::ActiveRecord::Base] &&
|
82
|
+
categories[::ActiveRecord::Base] != ::Switchman::Shard.current(::ActiveRecord::Base)
|
91
83
|
skip_delayed_job_auto_activation do
|
92
|
-
categories[
|
93
|
-
categories[
|
84
|
+
categories[::Delayed::Backend::ActiveRecord::AbstractJob] =
|
85
|
+
categories[::ActiveRecord::Base].delayed_jobs_shard
|
94
86
|
end
|
95
87
|
end
|
96
88
|
super
|
@@ -104,11 +96,6 @@ module SwitchmanInstJobs
|
|
104
96
|
@skip_delayed_job_auto_activation = was
|
105
97
|
end
|
106
98
|
|
107
|
-
def create
|
108
|
-
db = ::Switchman::DatabaseServer.server_for_new_shard
|
109
|
-
db.create_new_shard
|
110
|
-
end
|
111
|
-
|
112
99
|
def periodic_clear_shard_cache
|
113
100
|
# TODO: make this configurable
|
114
101
|
@timed_cache ||= TimedCache.new(-> { 60.to_i.seconds.ago }) do
|
data/lib/switchman_inst_jobs.rb
CHANGED
@@ -5,6 +5,9 @@ module SwitchmanInstJobs
|
|
5
5
|
cattr_accessor :delayed_jobs_shard_fallback
|
6
6
|
|
7
7
|
def self.initialize_active_record
|
8
|
+
::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(
|
9
|
+
ActiveRecord::ConnectionAdapters::ConnectionPool
|
10
|
+
)
|
8
11
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(
|
9
12
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
10
13
|
)
|
@@ -32,6 +35,7 @@ module SwitchmanInstJobs
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
38
|
+
require 'switchman_inst_jobs/active_record/connection_adapters/connection_pool'
|
35
39
|
require 'switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter'
|
36
40
|
require 'switchman_inst_jobs/active_record/migration'
|
37
41
|
require 'switchman_inst_jobs/delayed/settings'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman-inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Petty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inst-jobs
|
@@ -50,34 +50,40 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '6.1'
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '6.
|
56
|
+
version: '6.2'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
63
|
+
version: '6.1'
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '6.
|
66
|
+
version: '6.2'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: switchman
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '3.0'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.0.1
|
74
77
|
type: :runtime
|
75
78
|
prerelease: false
|
76
79
|
version_requirements: !ruby/object:Gem::Requirement
|
77
80
|
requirements:
|
78
81
|
- - "~>"
|
79
82
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
83
|
+
version: '3.0'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 3.0.1
|
81
87
|
- !ruby/object:Gem::Dependency
|
82
88
|
name: bundler
|
83
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,16 +116,16 @@ dependencies:
|
|
110
116
|
name: diplomat
|
111
117
|
requirement: !ruby/object:Gem::Requirement
|
112
118
|
requirements:
|
113
|
-
- - "
|
119
|
+
- - "~>"
|
114
120
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
121
|
+
version: 2.5.1
|
116
122
|
type: :development
|
117
123
|
prerelease: false
|
118
124
|
version_requirements: !ruby/object:Gem::Requirement
|
119
125
|
requirements:
|
120
|
-
- - "
|
126
|
+
- - "~>"
|
121
127
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
128
|
+
version: 2.5.1
|
123
129
|
- !ruby/object:Gem::Dependency
|
124
130
|
name: newrelic_rpm
|
125
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,70 +188,98 @@ dependencies:
|
|
182
188
|
requirements:
|
183
189
|
- - "~>"
|
184
190
|
- !ruby/object:Gem::Version
|
185
|
-
version: '3.
|
191
|
+
version: '3.10'
|
186
192
|
type: :development
|
187
193
|
prerelease: false
|
188
194
|
version_requirements: !ruby/object:Gem::Requirement
|
189
195
|
requirements:
|
190
196
|
- - "~>"
|
191
197
|
- !ruby/object:Gem::Version
|
192
|
-
version: '3.
|
198
|
+
version: '3.10'
|
193
199
|
- !ruby/object:Gem::Dependency
|
194
200
|
name: rspec-rails
|
195
201
|
requirement: !ruby/object:Gem::Requirement
|
196
202
|
requirements:
|
197
203
|
- - "~>"
|
198
204
|
- !ruby/object:Gem::Version
|
199
|
-
version: '
|
205
|
+
version: '5.0'
|
200
206
|
type: :development
|
201
207
|
prerelease: false
|
202
208
|
version_requirements: !ruby/object:Gem::Requirement
|
203
209
|
requirements:
|
204
210
|
- - "~>"
|
205
211
|
- !ruby/object:Gem::Version
|
206
|
-
version: '
|
212
|
+
version: '5.0'
|
207
213
|
- !ruby/object:Gem::Dependency
|
208
214
|
name: rubocop
|
209
215
|
requirement: !ruby/object:Gem::Requirement
|
210
216
|
requirements:
|
211
217
|
- - "~>"
|
212
218
|
- !ruby/object:Gem::Version
|
213
|
-
version: 1.
|
219
|
+
version: '1.15'
|
214
220
|
type: :development
|
215
221
|
prerelease: false
|
216
222
|
version_requirements: !ruby/object:Gem::Requirement
|
217
223
|
requirements:
|
218
224
|
- - "~>"
|
219
225
|
- !ruby/object:Gem::Version
|
220
|
-
version: 1.
|
226
|
+
version: '1.15'
|
221
227
|
- !ruby/object:Gem::Dependency
|
222
228
|
name: rubocop-rails
|
223
229
|
requirement: !ruby/object:Gem::Requirement
|
224
230
|
requirements:
|
225
231
|
- - "~>"
|
226
232
|
- !ruby/object:Gem::Version
|
227
|
-
version: 2.
|
233
|
+
version: '2.10'
|
234
|
+
type: :development
|
235
|
+
prerelease: false
|
236
|
+
version_requirements: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - "~>"
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: '2.10'
|
241
|
+
- !ruby/object:Gem::Dependency
|
242
|
+
name: rubocop-rake
|
243
|
+
requirement: !ruby/object:Gem::Requirement
|
244
|
+
requirements:
|
245
|
+
- - "~>"
|
246
|
+
- !ruby/object:Gem::Version
|
247
|
+
version: '0.6'
|
248
|
+
type: :development
|
249
|
+
prerelease: false
|
250
|
+
version_requirements: !ruby/object:Gem::Requirement
|
251
|
+
requirements:
|
252
|
+
- - "~>"
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: '0.6'
|
255
|
+
- !ruby/object:Gem::Dependency
|
256
|
+
name: rubocop-rspec
|
257
|
+
requirement: !ruby/object:Gem::Requirement
|
258
|
+
requirements:
|
259
|
+
- - "~>"
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: '2.4'
|
228
262
|
type: :development
|
229
263
|
prerelease: false
|
230
264
|
version_requirements: !ruby/object:Gem::Requirement
|
231
265
|
requirements:
|
232
266
|
- - "~>"
|
233
267
|
- !ruby/object:Gem::Version
|
234
|
-
version: 2.
|
268
|
+
version: '2.4'
|
235
269
|
- !ruby/object:Gem::Dependency
|
236
270
|
name: simplecov
|
237
271
|
requirement: !ruby/object:Gem::Requirement
|
238
272
|
requirements:
|
239
273
|
- - "~>"
|
240
274
|
- !ruby/object:Gem::Version
|
241
|
-
version: '0.
|
275
|
+
version: '0.21'
|
242
276
|
type: :development
|
243
277
|
prerelease: false
|
244
278
|
version_requirements: !ruby/object:Gem::Requirement
|
245
279
|
requirements:
|
246
280
|
- - "~>"
|
247
281
|
- !ruby/object:Gem::Version
|
248
|
-
version: '0.
|
282
|
+
version: '0.21'
|
249
283
|
- !ruby/object:Gem::Dependency
|
250
284
|
name: wwtd
|
251
285
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,6 +323,7 @@ files:
|
|
289
323
|
- db/migrate/20151210162949_improve_max_concurrent.rb
|
290
324
|
- db/migrate/20161206323555_add_back_default_string_limits_jobs.rb
|
291
325
|
- db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb
|
326
|
+
- db/migrate/20170308045401_add_delayed_jobs_shard_id_to_switchman_shards.rb
|
292
327
|
- db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb
|
293
328
|
- db/migrate/20190726154743_make_critical_columns_not_null.rb
|
294
329
|
- db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb
|
@@ -303,14 +338,9 @@ files:
|
|
303
338
|
- db/migrate/20210929204903_update_conflicting_singleton_function_to_use_index.rb
|
304
339
|
- db/migrate/20211101190934_update_after_delete_trigger_for_singleton_index.rb
|
305
340
|
- db/migrate/20211207094200_update_after_delete_trigger_for_singleton_transition_cases.rb
|
306
|
-
- db/migrate/20211220112800_fix_singleton_race_condition_insert.rb
|
307
|
-
- db/migrate/20211220113000_fix_singleton_race_condition_delete.rb
|
308
|
-
- db/migrate/20220127091200_fix_singleton_unique_constraint.rb
|
309
|
-
- db/migrate/20220128084800_update_insert_trigger_for_singleton_unique_constraint_change.rb
|
310
|
-
- db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb
|
311
|
-
- db/migrate/20220203063200_remove_old_singleton_index.rb
|
312
341
|
- lib/switchman-inst-jobs.rb
|
313
342
|
- lib/switchman_inst_jobs.rb
|
343
|
+
- lib/switchman_inst_jobs/active_record/connection_adapters/connection_pool.rb
|
314
344
|
- lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb
|
315
345
|
- lib/switchman_inst_jobs/active_record/migration.rb
|
316
346
|
- lib/switchman_inst_jobs/delayed/backend/base.rb
|