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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f9f61d51da46ec92185649cc434d9168740c491ade56179d13537d9552fa8b
|
4
|
+
data.tar.gz: 5c53dbe8087c254444f995ee738cb4164db03fc8a91ae823938a13b372e3eb0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c3483d276b435c93abc3547b458cde60739b9a4843465541065ae5d71eb8dcee9d2c4ebebf8b1fe4fc31fd6c7951f983d8af76c44a340e7e29ce811466778f
|
7
|
+
data.tar.gz: 0acdee9429002d28e9368bf29fce1b64fa492132f43b8ff884bca36f5b5aded965343a621c2e61b07de7bd18dcc059b5e11d1a8571a8319a0582d9dc8e1fa206
|
@@ -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
|
@@ -19,17 +21,13 @@ module SwitchmanInstJobs
|
|
19
21
|
|
20
22
|
# Ensure jobs get unblocked on the new shard if they exist
|
21
23
|
::Delayed::Worker.lifecycle.after(:perform) do |_worker, job|
|
22
|
-
if job.strand
|
23
|
-
column = job.strand ? :strand : :singleton
|
24
|
-
|
24
|
+
if job.strand
|
25
25
|
::Switchman::Shard.clear_cache
|
26
26
|
::Switchman::Shard.default.activate do
|
27
27
|
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
|
-
::Delayed::Job.where(
|
31
|
-
|
32
|
-
j = ::Delayed::Job.where(**{ column => job.try(column) }).next_in_strand_order.first
|
28
|
+
if current_job_shard != ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
|
29
|
+
current_job_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
|
30
|
+
j = ::Delayed::Job.where(strand: job.strand).next_in_strand_order.first
|
33
31
|
j.update_column(:next_in_strand, true) if j && !j.next_in_strand
|
34
32
|
end
|
35
33
|
end
|
@@ -47,7 +45,7 @@ module SwitchmanInstJobs
|
|
47
45
|
end
|
48
46
|
|
49
47
|
config.after_initialize do
|
50
|
-
::Switchman::Shard.default.delayed_jobs_shard.activate!(
|
48
|
+
::Switchman::Shard.default.delayed_jobs_shard.activate!(::Delayed::Backend::ActiveRecord::AbstractJob)
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|