switchman-inst-jobs 3.2.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +10 -9
- 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 +6 -4
- data/lib/switchman_inst_jobs/jobs_migrator.rb +23 -21
- 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 +8 -0
- metadata +39 -36
- data/db/migrate/20210809145804_add_n_strand_index.rb +0 -12
- data/db/migrate/20210812210128_add_singleton_column.rb +0 -200
- data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +0 -27
- data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +0 -56
- data/db/migrate/20210929204903_update_conflicting_singleton_function_to_use_index.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e76d31061b35e05fb85de802c868f5244c386f39490b236b7e2fa48160c1b4d
|
4
|
+
data.tar.gz: 81d2c12f67012e962b7d45157f5df7f045a3f4f0c45df2c9294661125524f234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb73f1c14a052801826a5f95cdfda52ecd73703cdc1b82b320a4b4ba69ba5ef2b4f77f01d41b1bec667df5b16a02529d8297f7de5726a392e65e086e0ad81570
|
7
|
+
data.tar.gz: 6b806f4e8e1e74e589090f75e54de9f12fe3e6ac5f97fc08296adc1c998055a082f7f815d0f7a6362d4745770e7791db100f640e6dadba5c8196ed0e940109b4
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class IndexJobsOnLockedBy < ActiveRecord::Migration[4.2]
|
2
|
-
disable_ddl_transaction!
|
2
|
+
disable_ddl_transaction!
|
3
3
|
|
4
4
|
def connection
|
5
|
-
Delayed::Backend::ActiveRecord::
|
5
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class AddJobsRunAtIndex < ActiveRecord::Migration[4.2]
|
2
|
-
disable_ddl_transaction!
|
2
|
+
disable_ddl_transaction!
|
3
3
|
|
4
4
|
def connection
|
5
|
-
Delayed::Backend::ActiveRecord::
|
5
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class CopyFailedJobsOriginalId < ActiveRecord::Migration[4.2]
|
2
2
|
def connection
|
3
|
-
Delayed::Backend::ActiveRecord::
|
3
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
4
4
|
end
|
5
5
|
|
6
6
|
def up
|
7
7
|
# this is a smaller, less frequently accessed table, so we just update all at once
|
8
|
-
Delayed::Backend::ActiveRecord::Job::Failed.where(
|
8
|
+
Delayed::Backend::ActiveRecord::Job::Failed.where(original_job_id: nil).update_all('original_job_id = original_id')
|
9
9
|
end
|
10
10
|
|
11
11
|
def down; end
|
@@ -2,7 +2,7 @@ class AddShardIdToDelayedJobs < ActiveRecord::Migration[4.2]
|
|
2
2
|
disable_ddl_transaction!
|
3
3
|
|
4
4
|
def connection
|
5
|
-
Delayed::Backend::ActiveRecord::
|
5
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
@@ -11,19 +11,9 @@ class AddShardIdToDelayedJobs < ActiveRecord::Migration[4.2]
|
|
11
11
|
|
12
12
|
add_column :failed_jobs, :shard_id, :integer, limit: 8
|
13
13
|
add_index :failed_jobs, :shard_id, algorithm: :concurrently
|
14
|
-
|
15
|
-
add_column :switchman_shards, :delayed_jobs_shard_id, :integer, limit: 8
|
16
|
-
add_foreign_key(
|
17
|
-
:switchman_shards,
|
18
|
-
:switchman_shards,
|
19
|
-
column: :delayed_jobs_shard_id
|
20
|
-
)
|
21
14
|
end
|
22
15
|
|
23
16
|
def down
|
24
|
-
remove_foreign_key :switchman_shards, column: :delayed_jobs_shard_id
|
25
|
-
remove_column :switchman_shards, :delayed_jobs_shard_id
|
26
|
-
|
27
17
|
remove_index :failed_jobs, :shard_id
|
28
18
|
remove_column :failed_jobs, :shard_id
|
29
19
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
|
2
|
-
disable_ddl_transaction!
|
2
|
+
disable_ddl_transaction!
|
3
3
|
|
4
4
|
def connection
|
5
|
-
Delayed::
|
5
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class AddStrandOrderOverride < ActiveRecord::Migration[4.2]
|
2
|
-
disable_ddl_transaction!
|
2
|
+
disable_ddl_transaction!
|
3
3
|
|
4
4
|
def connection
|
5
|
-
Delayed::
|
5
|
+
Delayed::Backend::ActiveRecord::AbstractJob.connection
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SwitchmanInstJobs
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module ConnectionPool
|
5
|
+
def shard
|
6
|
+
if connection_klass == ::Delayed::Backend::ActiveRecord::AbstractJob
|
7
|
+
return shard_stack.last || ::Switchman::Shard.current(::ActiveRecord::Base).delayed_jobs_shard
|
8
|
+
end
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -24,19 +24,18 @@ module SwitchmanInstJobs
|
|
24
24
|
# In general this will only happen in unusual circumstances like tests
|
25
25
|
# also if migrations are running, always use the current shard's job shard
|
26
26
|
if ::ActiveRecord::Migration.open_migrations.zero? &&
|
27
|
-
current_shard.delayed_jobs_shard !=
|
27
|
+
current_shard.delayed_jobs_shard !=
|
28
|
+
::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
28
29
|
enqueue_job.call
|
29
30
|
else
|
30
|
-
::Switchman::Shard.
|
31
|
-
current_shard = ::Switchman::Shard.lookup(current_shard.id)
|
32
|
-
end
|
31
|
+
current_shard = ::Switchman::Shard.lookup(current_shard.id)
|
33
32
|
current_job_shard = current_shard.delayed_jobs_shard
|
34
33
|
|
35
34
|
if (options[:singleton] || options[:strand]) && current_shard.block_stranded
|
36
35
|
enqueue_options[:next_in_strand] = false
|
37
36
|
end
|
38
37
|
|
39
|
-
current_job_shard.activate(
|
38
|
+
current_job_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
40
39
|
enqueue_job.call
|
41
40
|
end
|
42
41
|
end
|
@@ -50,7 +49,7 @@ module SwitchmanInstJobs
|
|
50
49
|
shard_ids = configured_shard_ids
|
51
50
|
if shard_ids.any?
|
52
51
|
shards = shard_ids.map { |shard_id| ::Delayed::Worker.shard(shard_id) }
|
53
|
-
::Switchman::Shard.with_each_shard(shards, [
|
52
|
+
::Switchman::Shard.with_each_shard(shards, [::Delayed::Backend::ActiveRecord::AbstractJob]) do
|
54
53
|
super
|
55
54
|
end
|
56
55
|
else
|
@@ -61,7 +60,9 @@ module SwitchmanInstJobs
|
|
61
60
|
|
62
61
|
def self.prepended(base)
|
63
62
|
base.singleton_class.prepend(ClassMethods)
|
64
|
-
|
63
|
+
return unless base.name == 'Delayed::Backend::ActiveRecord::Job'
|
64
|
+
|
65
|
+
::Delayed::Backend::ActiveRecord::AbstractJob.sharded_model
|
65
66
|
end
|
66
67
|
|
67
68
|
def current_shard
|
@@ -73,7 +74,7 @@ module SwitchmanInstJobs
|
|
73
74
|
self.shard_id = shard.id
|
74
75
|
self.shard_id = nil if shard.is_a?(::Switchman::DefaultShard)
|
75
76
|
# If jobs are held for a shard, enqueue new ones as held as well
|
76
|
-
return unless
|
77
|
+
return unless shard.jobs_held
|
77
78
|
|
78
79
|
self.locked_by = ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY
|
79
80
|
self.locked_at = ::Delayed::Job.db_time_now
|
@@ -90,7 +91,7 @@ module SwitchmanInstJobs
|
|
90
91
|
raise ShardNotFoundError, shard_id unless current_shard
|
91
92
|
|
92
93
|
current_shard.activate { super }
|
93
|
-
rescue
|
94
|
+
rescue PG::ConnectionBad, PG::UndefinedTable
|
94
95
|
# likely a missing shard with a stale cache
|
95
96
|
current_shard.send(:clear_cache)
|
96
97
|
::Switchman::Shard.clear_cache
|
@@ -20,7 +20,7 @@ module SwitchmanInstJobs
|
|
20
20
|
shard_ids = @config[:workers].pluck(:shard).uniq
|
21
21
|
shards = shard_ids.map { |shard_id| ::Delayed::Worker.shard(shard_id) }
|
22
22
|
end
|
23
|
-
::Switchman::Shard.with_each_shard(shards, [
|
23
|
+
::Switchman::Shard.with_each_shard(shards, [::Delayed::Backend::ActiveRecord::AbstractJob]) do
|
24
24
|
super
|
25
25
|
end
|
26
26
|
end
|
@@ -21,18 +21,16 @@ module SwitchmanInstJobs
|
|
21
21
|
def reschedule_abandoned_jobs
|
22
22
|
shard_ids = ::SwitchmanInstJobs::Delayed::Settings.configured_shard_ids
|
23
23
|
shards = shard_ids.map { |shard_id| ::Delayed::Worker.shard(shard_id) }
|
24
|
-
::Switchman::Shard.with_each_shard(shards,
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
super()
|
35
|
-
end
|
24
|
+
::Switchman::Shard.with_each_shard(shards,
|
25
|
+
[::ActiveRecord::Base, ::Delayed::Backend::ActiveRecord::AbstractJob]) do
|
26
|
+
munge_service_name(::Switchman::Shard.current) do
|
27
|
+
# because this rescheduling process is running on every host, we need
|
28
|
+
# to make sure that it's functioning for each shard the current
|
29
|
+
# host is programmed to interact with, but ONLY for those shards.
|
30
|
+
# reading the config lets us iterate over any shards this host should
|
31
|
+
# work with and lets us pick the correct service name to identify which
|
32
|
+
# hosts are currently alive and valid via the health checks
|
33
|
+
super()
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -16,14 +16,14 @@ module SwitchmanInstJobs
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def start
|
19
|
-
shard.activate(
|
19
|
+
shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) { super }
|
20
20
|
end
|
21
21
|
|
22
22
|
# Worker#run is usually only called from Worker#start, but if the worker
|
23
23
|
# is called directly from the console, we want to make sure it still gets
|
24
24
|
# the right shard activated.
|
25
25
|
def run
|
26
|
-
shard.activate(
|
26
|
+
shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) { super }
|
27
27
|
end
|
28
28
|
|
29
29
|
def shard
|
@@ -11,7 +11,9 @@ module SwitchmanInstJobs
|
|
11
11
|
|
12
12
|
::Delayed::Worker.lifecycle.around(:work_queue_pop) do |worker, config, &block|
|
13
13
|
if config[:shard]
|
14
|
-
::Switchman::Shard.lookup(config[:shard]).activate(
|
14
|
+
::Switchman::Shard.lookup(config[:shard]).activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
15
|
+
block.call(worker, config)
|
16
|
+
end
|
15
17
|
else
|
16
18
|
block.call(worker, config)
|
17
19
|
end
|
@@ -23,8 +25,8 @@ module SwitchmanInstJobs
|
|
23
25
|
::Switchman::Shard.clear_cache
|
24
26
|
::Switchman::Shard.default.activate do
|
25
27
|
current_job_shard = ::Switchman::Shard.lookup(job.shard_id).delayed_jobs_shard
|
26
|
-
if current_job_shard != ::Switchman::Shard.current(
|
27
|
-
current_job_shard.activate(
|
28
|
+
if current_job_shard != ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
29
|
+
current_job_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
28
30
|
j = ::Delayed::Job.where(strand: job.strand).next_in_strand_order.first
|
29
31
|
j.update_column(:next_in_strand, true) if j && !j.next_in_strand
|
30
32
|
end
|
@@ -43,7 +45,7 @@ module SwitchmanInstJobs
|
|
43
45
|
end
|
44
46
|
|
45
47
|
config.after_initialize do
|
46
|
-
::Switchman::Shard.default.delayed_jobs_shard.activate!(
|
48
|
+
::Switchman::Shard.default.delayed_jobs_shard.activate!(::Delayed::Backend::ActiveRecord::AbstractJob)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Just disabling all the rubocop metrics for this file for now,
|
2
|
+
# as it is a direct port-in of existing code
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/BlockLength, Metrics/MethodLength, Metrics/AbcSize, Metrics/ClassLength
|
1
5
|
require 'set'
|
2
6
|
require 'parallel'
|
3
7
|
|
@@ -13,10 +17,10 @@ module SwitchmanInstJobs
|
|
13
17
|
return yield if shards.empty?
|
14
18
|
|
15
19
|
shard = shards.pop
|
16
|
-
current_shard = ::Switchman::Shard.current(
|
17
|
-
shard.activate(
|
20
|
+
current_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
21
|
+
shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
18
22
|
::Delayed::Job.transaction do
|
19
|
-
current_shard.activate(
|
23
|
+
current_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
20
24
|
transaction_on(shards, &block)
|
21
25
|
end
|
22
26
|
end
|
@@ -45,11 +49,11 @@ module SwitchmanInstJobs
|
|
45
49
|
# rubocop:disable Style/CombinableLoops
|
46
50
|
# We first migrate strands so that we can stop blocking strands before we migrate unstranded jobs
|
47
51
|
source_shards.each do |s|
|
48
|
-
::Switchman::Shard.lookup(s).activate(
|
52
|
+
::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_strands }
|
49
53
|
end
|
50
54
|
|
51
55
|
source_shards.each do |s|
|
52
|
-
::Switchman::Shard.lookup(s).activate(
|
56
|
+
::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_everything }
|
53
57
|
end
|
54
58
|
ensure_unblock_stranded_for(shard_map.map(&:first))
|
55
59
|
# rubocop:enable Style/CombinableLoops
|
@@ -99,7 +103,7 @@ module SwitchmanInstJobs
|
|
99
103
|
# 4) no running job, jobs moved: set next_in_strand=true on the first of
|
100
104
|
# those (= do nothing since it should already be true)
|
101
105
|
|
102
|
-
source_shard = ::Switchman::Shard.current(
|
106
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
103
107
|
strand_scope = ::Delayed::Job.shard(source_shard).where.not(strand: nil)
|
104
108
|
shard_map = build_shard_map(strand_scope, source_shard)
|
105
109
|
shard_map.each do |(target_shard, source_shard_ids)|
|
@@ -108,7 +112,7 @@ module SwitchmanInstJobs
|
|
108
112
|
# 1) is taken care of because it should not show up here in strands
|
109
113
|
strands = shard_scope.distinct.order(:strand).pluck(:strand)
|
110
114
|
|
111
|
-
target_shard.activate(
|
115
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
112
116
|
strands.each do |strand|
|
113
117
|
transaction_on([source_shard, target_shard]) do
|
114
118
|
this_strand_scope = shard_scope.where(strand: strand)
|
@@ -167,7 +171,7 @@ module SwitchmanInstJobs
|
|
167
171
|
end
|
168
172
|
|
169
173
|
def unblock_strands(target_shard)
|
170
|
-
target_shard.activate(
|
174
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
171
175
|
loop do
|
172
176
|
# We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
|
173
177
|
# to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
|
@@ -186,8 +190,8 @@ module SwitchmanInstJobs
|
|
186
190
|
end
|
187
191
|
|
188
192
|
def migrate_everything
|
189
|
-
source_shard = ::Switchman::Shard.current(
|
190
|
-
scope = ::Delayed::Job.shard(source_shard).where(
|
193
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
194
|
+
scope = ::Delayed::Job.shard(source_shard).where(strand: nil)
|
191
195
|
|
192
196
|
shard_map = build_shard_map(scope, source_shard)
|
193
197
|
shard_map.each do |(target_shard, source_shard_ids)|
|
@@ -220,7 +224,7 @@ module SwitchmanInstJobs
|
|
220
224
|
# Adapted from get_and_lock_next_available in delayed/backend/active_record.rb
|
221
225
|
target_jobs = scope.limit(1000).lock('FOR UPDATE SKIP LOCKED')
|
222
226
|
|
223
|
-
query = source_shard.activate(
|
227
|
+
query = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
224
228
|
"WITH limited_jobs AS (#{target_jobs.to_sql}) " \
|
225
229
|
"UPDATE #{::Delayed::Job.quoted_table_name} " \
|
226
230
|
"SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)}, " \
|
@@ -229,7 +233,9 @@ module SwitchmanInstJobs
|
|
229
233
|
"RETURNING #{::Delayed::Job.quoted_table_name}.*"
|
230
234
|
end
|
231
235
|
|
232
|
-
jobs = source_shard.activate(
|
236
|
+
jobs = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
237
|
+
::Delayed::Job.find_by_sql(query)
|
238
|
+
end
|
233
239
|
new_jobs = jobs.map do |job|
|
234
240
|
new_job = job.dup
|
235
241
|
new_job.shard = target_shard
|
@@ -247,10 +253,10 @@ module SwitchmanInstJobs
|
|
247
253
|
new_job
|
248
254
|
end
|
249
255
|
transaction_on([source_shard, target_shard]) do
|
250
|
-
target_shard.activate(
|
256
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
251
257
|
bulk_insert_jobs(new_jobs)
|
252
258
|
end
|
253
|
-
source_shard.activate(
|
259
|
+
source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
254
260
|
::Delayed::Job.delete(jobs)
|
255
261
|
end
|
256
262
|
end
|
@@ -277,10 +283,7 @@ module SwitchmanInstJobs
|
|
277
283
|
connection = ::Delayed::Job.connection
|
278
284
|
quoted_keys = keys.map { |k| connection.quote_column_name(k) }.join(', ')
|
279
285
|
|
280
|
-
connection.execute
|
281
|
-
connection.execute "CREATE TEMPORARY TABLE delayed_jobs_bulk_copy
|
282
|
-
(LIKE #{::Delayed::Job.quoted_table_name} INCLUDING DEFAULTS)"
|
283
|
-
connection.execute "COPY delayed_jobs_bulk_copy (#{quoted_keys}) FROM STDIN"
|
286
|
+
connection.execute "COPY #{::Delayed::Job.quoted_table_name} (#{quoted_keys}) FROM STDIN"
|
284
287
|
records.map do |record|
|
285
288
|
connection.raw_connection.put_copy_data("#{keys.map { |k| quote_text(record[k]) }.join("\t")}\n")
|
286
289
|
end
|
@@ -292,9 +295,6 @@ module SwitchmanInstJobs
|
|
292
295
|
rescue StandardError => e
|
293
296
|
raise connection.send(:translate_exception, e, 'COPY FROM STDIN')
|
294
297
|
end
|
295
|
-
connection.execute "INSERT INTO #{::Delayed::Job.quoted_table_name} (#{quoted_keys})
|
296
|
-
SELECT #{quoted_keys} FROM delayed_jobs_bulk_copy
|
297
|
-
ON CONFLICT (singleton) WHERE singleton IS NOT NULL AND locked_by IS NULL DO NOTHING"
|
298
298
|
result.cmd_tuples
|
299
299
|
end
|
300
300
|
|
@@ -312,3 +312,5 @@ module SwitchmanInstJobs
|
|
312
312
|
end
|
313
313
|
end
|
314
314
|
end
|
315
|
+
|
316
|
+
# rubocop:enable Metrics/BlockLength, Metrics/MethodLength, Metrics/AbcSize, Metrics/ClassLength
|