switchman-inst-jobs 3.2.8 → 4.0.4
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 +6 -4
- data/lib/switchman_inst_jobs/jobs_migrator.rb +26 -22
- 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 +57 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1540b8c0c200ee917338953c9ea377dc0f32f354175e0e6953435861333c5f
|
4
|
+
data.tar.gz: 4e3912c490226c6f73c39d5923199e8d9cd661c8caeb6cef2fd6701b0dc5c08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee661bcf6f5335a5c6d4d7651936de85aedc6b01221700353b97c5bde61dc9a6c351948daaea70689e401962c4249efe56d359e377636dafafecb8d09ee4a49
|
7
|
+
data.tar.gz: 91b155c2f00a89298a7c9de0b1ec854119534e92ae6e7d89b3823adf666ba0fc9ca045c2a4e10e2e0a337c3eb3a8f1d775a6718ae9adde7d396ee787164e0596
|
@@ -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
|
@@ -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
|
@@ -25,8 +27,8 @@ module SwitchmanInstJobs
|
|
25
27
|
::Switchman::Shard.clear_cache
|
26
28
|
::Switchman::Shard.default.activate do
|
27
29
|
current_job_shard = ::Switchman::Shard.lookup(job.shard_id).delayed_jobs_shard
|
28
|
-
if current_job_shard != ::Switchman::Shard.current(
|
29
|
-
current_job_shard.activate(
|
30
|
+
if current_job_shard != ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
31
|
+
current_job_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
30
32
|
::Delayed::Job.where(source: 'JobsMigrator::StrandBlocker', **{ column => job.try(column) }).delete_all
|
31
33
|
|
32
34
|
j = ::Delayed::Job.where(**{ column => job.try(column) }).next_in_strand_order.first
|
@@ -47,7 +49,7 @@ module SwitchmanInstJobs
|
|
47
49
|
end
|
48
50
|
|
49
51
|
config.after_initialize do
|
50
|
-
::Switchman::Shard.default.delayed_jobs_shard.activate!(
|
52
|
+
::Switchman::Shard.default.delayed_jobs_shard.activate!(::Delayed::Backend::ActiveRecord::AbstractJob)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -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
|
@@ -90,7 +90,7 @@ module SwitchmanInstJobs
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def migrate_strands(batch_size: 1_000)
|
93
|
-
source_shard = ::Switchman::Shard.current(
|
93
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
94
94
|
|
95
95
|
# there are 4 scenarios to deal with here
|
96
96
|
# 1) no running job, no jobs moved: do nothing
|
@@ -108,7 +108,7 @@ module SwitchmanInstJobs
|
|
108
108
|
# 1) is taken care of because it should not show up here in strands
|
109
109
|
values = shard_scope.distinct.order(column).pluck(column)
|
110
110
|
|
111
|
-
target_shard.activate(
|
111
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
112
112
|
values.each do |value|
|
113
113
|
transaction_on([source_shard, target_shard]) do
|
114
114
|
value_scope = shard_scope.where(**{ column => value })
|
@@ -157,7 +157,7 @@ module SwitchmanInstJobs
|
|
157
157
|
|
158
158
|
shard_map = build_shard_map(all_scope, source_shard)
|
159
159
|
shard_map.each do |(target_shard, source_shard_ids)|
|
160
|
-
target_shard.activate(
|
160
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
161
161
|
updated = ::Switchman::Shard.where(id: source_shard_ids, block_stranded: true).
|
162
162
|
update_all(block_stranded: false)
|
163
163
|
# If this is being manually re-run for some reason to clean something up, don't wait for nothing to happen
|
@@ -187,7 +187,7 @@ module SwitchmanInstJobs
|
|
187
187
|
order(column, :strand_order_override, :id)).limit(batch_size)
|
188
188
|
}
|
189
189
|
|
190
|
-
target_shard.activate(
|
190
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
191
191
|
# We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
|
192
192
|
# to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
|
193
193
|
# this target shard, so we shouldn't unlock them yet. We only ever unlock one job here to keep the
|
@@ -206,8 +206,8 @@ module SwitchmanInstJobs
|
|
206
206
|
end
|
207
207
|
|
208
208
|
def migrate_everything(batch_size: 1_000)
|
209
|
-
source_shard = ::Switchman::Shard.current(
|
210
|
-
scope = ::Delayed::Job.shard(source_shard).where(
|
209
|
+
source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
210
|
+
scope = ::Delayed::Job.shard(source_shard).where(strand: nil)
|
211
211
|
|
212
212
|
shard_map = build_shard_map(scope, source_shard)
|
213
213
|
shard_map.each do |(target_shard, source_shard_ids)|
|
@@ -253,16 +253,20 @@ module SwitchmanInstJobs
|
|
253
253
|
# Adapted from get_and_lock_next_available in delayed/backend/active_record.rb
|
254
254
|
target_jobs = scope.limit(batch_size).lock('FOR UPDATE SKIP LOCKED')
|
255
255
|
|
256
|
-
query = source_shard.activate(
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
256
|
+
query = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
257
|
+
<<~SQL
|
258
|
+
WITH limited_jobs AS (#{target_jobs.to_sql})
|
259
|
+
UPDATE #{::Delayed::Job.quoted_table_name}
|
260
|
+
SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)},
|
261
|
+
locked_at = #{::Delayed::Job.connection.quote(::Delayed::Job.db_time_now)}
|
262
|
+
FROM limited_jobs WHERE limited_jobs.id=#{::Delayed::Job.quoted_table_name}.id
|
263
|
+
RETURNING #{::Delayed::Job.quoted_table_name}.*
|
264
|
+
SQL
|
263
265
|
end
|
264
266
|
|
265
|
-
jobs = source_shard.activate(
|
267
|
+
jobs = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
268
|
+
::Delayed::Job.find_by_sql(query)
|
269
|
+
end
|
266
270
|
new_jobs = jobs.map do |job|
|
267
271
|
new_job = job.dup
|
268
272
|
new_job.shard = target_shard
|
@@ -280,10 +284,10 @@ module SwitchmanInstJobs
|
|
280
284
|
new_job
|
281
285
|
end
|
282
286
|
transaction_on([source_shard, target_shard]) do
|
283
|
-
target_shard.activate(
|
287
|
+
target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
284
288
|
bulk_insert_jobs(new_jobs)
|
285
289
|
end
|
286
|
-
source_shard.activate(
|
290
|
+
source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
287
291
|
::Delayed::Job.delete(jobs)
|
288
292
|
end
|
289
293
|
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,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Petty
|
@@ -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
|
@@ -311,6 +346,7 @@ files:
|
|
311
346
|
- db/migrate/20220203063200_remove_old_singleton_index.rb
|
312
347
|
- lib/switchman-inst-jobs.rb
|
313
348
|
- lib/switchman_inst_jobs.rb
|
349
|
+
- lib/switchman_inst_jobs/active_record/connection_adapters/connection_pool.rb
|
314
350
|
- lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb
|
315
351
|
- lib/switchman_inst_jobs/active_record/migration.rb
|
316
352
|
- lib/switchman_inst_jobs/delayed/backend/base.rb
|