switchman-inst-jobs 3.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +1 -1
  3. data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +1 -1
  4. data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +1 -1
  5. data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +1 -1
  6. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +1 -1
  7. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +1 -1
  8. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +1 -1
  9. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +1 -1
  10. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -1
  11. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +1 -1
  12. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -2
  13. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
  14. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
  15. data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +1 -1
  16. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -2
  17. data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +1 -1
  18. data/db/migrate/20140512213941_add_source_to_jobs.rb +1 -1
  19. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +1 -1
  20. data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +1 -1
  21. data/db/migrate/20151210162949_improve_max_concurrent.rb +1 -1
  22. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +1 -1
  23. data/db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb +1 -11
  24. data/db/migrate/20170308045401_add_delayed_jobs_shard_id_to_switchman_shards.rb +5 -0
  25. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +1 -1
  26. data/db/migrate/20190726154743_make_critical_columns_not_null.rb +1 -1
  27. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -2
  28. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +1 -1
  29. data/db/migrate/20200825011002_add_strand_order_override.rb +2 -2
  30. data/lib/switchman_inst_jobs.rb +4 -0
  31. data/lib/switchman_inst_jobs/active_record/connection_adapters/connection_pool.rb +15 -0
  32. data/lib/switchman_inst_jobs/delayed/backend/base.rb +12 -9
  33. data/lib/switchman_inst_jobs/delayed/pool.rb +1 -1
  34. data/lib/switchman_inst_jobs/delayed/worker.rb +2 -2
  35. data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +10 -12
  36. data/lib/switchman_inst_jobs/engine.rb +6 -4
  37. data/lib/switchman_inst_jobs/jobs_migrator.rb +16 -14
  38. data/lib/switchman_inst_jobs/switchman/shard.rb +8 -21
  39. data/lib/switchman_inst_jobs/version.rb +1 -1
  40. metadata +45 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4efbe05e879c9162df06f945af688c64876b9c56cc870509687160549359fd39
4
- data.tar.gz: e32c8a6dfecd0b6c760d07a4d45eeaf6651d6cc7e70e7b6418d82c5a112f70cd
3
+ metadata.gz: 1e76d31061b35e05fb85de802c868f5244c386f39490b236b7e2fa48160c1b4d
4
+ data.tar.gz: 81d2c12f67012e962b7d45157f5df7f045a3f4f0c45df2c9294661125524f234
5
5
  SHA512:
6
- metadata.gz: 4fe0103d1b4bc305f0c85ba2135366968eb7c33bb6482b6d302dde9b9532db1d3d09fac64d90dad16fe6c6a438236ede5732d16a22d8538053d814010c9d2c87
7
- data.tar.gz: feb2e546ee06bc38f964f58e63cfb59fdc25757952762ef8f8faf0521050d264e9f018ea8e6bb0131b277997d63035f68562cf45a7af13886fbfd80f481f5515
6
+ metadata.gz: cb73f1c14a052801826a5f95cdfda52ecd73703cdc1b82b320a4b4ba69ba5ef2b4f77f01d41b1bec667df5b16a02529d8297f7de5726a392e65e086e0ad81570
7
+ data.tar.gz: 6b806f4e8e1e74e589090f75e54de9f12fe3e6ac5f97fc08296adc1c998055a082f7f815d0f7a6362d4745770e7791db100f640e6dadba5c8196ed0e940109b4
@@ -1,6 +1,6 @@
1
1
  class CreateDelayedJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddDelayedJobsTag < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddDelayedJobsMaxAttempts < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddDelayedJobsStrand < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class CleanupDelayedJobsIndexes < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class OptimizeDelayedJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddDelayedJobsNextInStrand < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class DelayedJobsDeleteTriggerLockForUpdate < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class DropPsqlJobsPopFn < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,8 +1,8 @@
1
1
  class IndexJobsOnLockedBy < ActiveRecord::Migration[4.2]
2
- disable_ddl_transaction! if respond_to?(:disable_ddl_transaction!)
2
+ disable_ddl_transaction!
3
3
 
4
4
  def connection
5
- Delayed::Backend::ActiveRecord::Job.connection
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! if respond_to?(:disable_ddl_transaction!)
2
+ disable_ddl_transaction!
3
3
 
4
4
  def connection
5
- Delayed::Backend::ActiveRecord::Job.connection
5
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
6
6
  end
7
7
 
8
8
  def up
@@ -1,6 +1,6 @@
1
1
  class ChangeDelayedJobsHandlerToText < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddFailedJobsOriginalJobId < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,11 +1,11 @@
1
1
  class CopyFailedJobsOriginalId < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
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('original_job_id is null').update_all('original_job_id = original_id')
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
@@ -1,6 +1,6 @@
1
1
  class DropFailedJobsOriginalId < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Backend::ActiveRecord::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddSourceToJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddExpiresAtToJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class ImproveMaxConcurrent < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class AddBackDefaultStringLimitsJobs < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -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::Job.connection
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
 
@@ -0,0 +1,5 @@
1
+ class AddDelayedJobsShardIdToSwitchmanShards < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_reference :switchman_shards, :delayed_jobs_shard, foreign_key: { to_table: :switchman_shards }, index: false, if_not_exists: true
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,6 +1,6 @@
1
1
  class MakeCriticalColumnsNotNull < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,8 +1,8 @@
1
1
  class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
2
- disable_ddl_transaction! if respond_to?(:disable_ddl_transaction!)
2
+ disable_ddl_transaction!
3
3
 
4
4
  def connection
5
- Delayed::Job.connection
5
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
6
6
  end
7
7
 
8
8
  def up
@@ -1,6 +1,6 @@
1
1
  class SpeedUpMaxConcurrentDeleteTrigger < ActiveRecord::Migration[4.2]
2
2
  def connection
3
- Delayed::Job.connection
3
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
4
4
  end
5
5
 
6
6
  def up
@@ -1,8 +1,8 @@
1
1
  class AddStrandOrderOverride < ActiveRecord::Migration[4.2]
2
- disable_ddl_transaction! if respond_to?(:disable_ddl_transaction!)
2
+ disable_ddl_transaction!
3
3
 
4
4
  def connection
5
- Delayed::Job.connection
5
+ Delayed::Backend::ActiveRecord::AbstractJob.connection
6
6
  end
7
7
 
8
8
  def up
@@ -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
  )
@@ -36,6 +39,7 @@ module SwitchmanInstJobs
36
39
  end
37
40
  end
38
41
 
42
+ require 'switchman_inst_jobs/active_record/connection_adapters/connection_pool'
39
43
  require 'switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter'
40
44
  require 'switchman_inst_jobs/active_record/migration'
41
45
  require 'switchman_inst_jobs/delayed/settings'
@@ -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
@@ -18,25 +18,24 @@ module SwitchmanInstJobs
18
18
  enqueue_options = options.merge(
19
19
  current_shard: current_shard
20
20
  )
21
- enqueue_job = -> { ::GuardRail.activate(:master) { super(object, **enqueue_options) } }
21
+ enqueue_job = -> { ::GuardRail.activate(:primary) { super(object, **enqueue_options) } }
22
22
 
23
23
  # Another dj shard must be currently manually activated, so just use that
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 != ::Switchman::Shard.current(:delayed_jobs)
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.default.activate do
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(:delayed_jobs) do
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, [:delayed_jobs]) do
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
- base.shard_category = :delayed_jobs if base.name == 'Delayed::Backend::ActiveRecord::Job'
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
@@ -81,6 +82,8 @@ module SwitchmanInstJobs
81
82
  end
82
83
 
83
84
  def invoke_job
85
+ raise ShardNotFoundError, shard_id unless current_shard
86
+
84
87
  current_shard.activate { super }
85
88
  end
86
89
 
@@ -88,7 +91,7 @@ module SwitchmanInstJobs
88
91
  raise ShardNotFoundError, shard_id unless current_shard
89
92
 
90
93
  current_shard.activate { super }
91
- rescue ::Switchman::ConnectionError, PG::ConnectionBad, PG::UndefinedTable
94
+ rescue PG::ConnectionBad, PG::UndefinedTable
92
95
  # likely a missing shard with a stale cache
93
96
  current_shard.send(:clear_cache)
94
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, [:delayed_jobs]) do
23
+ ::Switchman::Shard.with_each_shard(shards, [::Delayed::Backend::ActiveRecord::AbstractJob]) do
24
24
  super
25
25
  end
26
26
  end
@@ -16,14 +16,14 @@ module SwitchmanInstJobs
16
16
  end
17
17
 
18
18
  def start
19
- shard.activate(:delayed_jobs) { super }
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(:delayed_jobs) { super }
26
+ shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) { super }
27
27
  end
28
28
 
29
29
  def shard
@@ -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, [:delayed_jobs]) do
25
- dj_shard = ::Switchman::Shard.current(:delayed_jobs)
26
- dj_shard.activate do
27
- munge_service_name(dj_shard) do
28
- # because this rescheduling process is running on every host, we need
29
- # to make sure that it's functioning for each shard the current
30
- # host is programmed to interact with, but ONLY for those shards.
31
- # reading the config lets us iterate over any shards this host should
32
- # work with and lets us pick the correct service name to identify which
33
- # hosts are currently alive and valid via the health checks
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
@@ -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(:delayed_jobs) { block.call(worker, config) }
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(:delayed_jobs)
27
- current_job_shard.activate(:delayed_jobs) do
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!(:delayed_jobs)
48
+ ::Switchman::Shard.default.delayed_jobs_shard.activate!(::Delayed::Backend::ActiveRecord::AbstractJob)
47
49
  end
48
50
  end
49
51
  end
@@ -17,10 +17,10 @@ module SwitchmanInstJobs
17
17
  return yield if shards.empty?
18
18
 
19
19
  shard = shards.pop
20
- current_shard = ::Switchman::Shard.current(:delayed_jobs)
21
- shard.activate(:delayed_jobs) do
20
+ current_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
21
+ shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
22
22
  ::Delayed::Job.transaction do
23
- current_shard.activate(:delayed_jobs) do
23
+ current_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
24
24
  transaction_on(shards, &block)
25
25
  end
26
26
  end
@@ -49,11 +49,11 @@ module SwitchmanInstJobs
49
49
  # rubocop:disable Style/CombinableLoops
50
50
  # We first migrate strands so that we can stop blocking strands before we migrate unstranded jobs
51
51
  source_shards.each do |s|
52
- ::Switchman::Shard.lookup(s).activate(:delayed_jobs) { migrate_strands }
52
+ ::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_strands }
53
53
  end
54
54
 
55
55
  source_shards.each do |s|
56
- ::Switchman::Shard.lookup(s).activate(:delayed_jobs) { migrate_everything }
56
+ ::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_everything }
57
57
  end
58
58
  ensure_unblock_stranded_for(shard_map.map(&:first))
59
59
  # rubocop:enable Style/CombinableLoops
@@ -103,7 +103,7 @@ module SwitchmanInstJobs
103
103
  # 4) no running job, jobs moved: set next_in_strand=true on the first of
104
104
  # those (= do nothing since it should already be true)
105
105
 
106
- source_shard = ::Switchman::Shard.current(:delayed_jobs)
106
+ source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
107
107
  strand_scope = ::Delayed::Job.shard(source_shard).where.not(strand: nil)
108
108
  shard_map = build_shard_map(strand_scope, source_shard)
109
109
  shard_map.each do |(target_shard, source_shard_ids)|
@@ -112,7 +112,7 @@ module SwitchmanInstJobs
112
112
  # 1) is taken care of because it should not show up here in strands
113
113
  strands = shard_scope.distinct.order(:strand).pluck(:strand)
114
114
 
115
- target_shard.activate(:delayed_jobs) do
115
+ target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
116
116
  strands.each do |strand|
117
117
  transaction_on([source_shard, target_shard]) do
118
118
  this_strand_scope = shard_scope.where(strand: strand)
@@ -171,7 +171,7 @@ module SwitchmanInstJobs
171
171
  end
172
172
 
173
173
  def unblock_strands(target_shard)
174
- target_shard.activate(:delayed_jobs) do
174
+ target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
175
175
  loop do
176
176
  # We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
177
177
  # to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
@@ -190,8 +190,8 @@ module SwitchmanInstJobs
190
190
  end
191
191
 
192
192
  def migrate_everything
193
- source_shard = ::Switchman::Shard.current(:delayed_jobs)
194
- scope = ::Delayed::Job.shard(source_shard).where('strand IS NULL')
193
+ source_shard = ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob)
194
+ scope = ::Delayed::Job.shard(source_shard).where(strand: nil)
195
195
 
196
196
  shard_map = build_shard_map(scope, source_shard)
197
197
  shard_map.each do |(target_shard, source_shard_ids)|
@@ -224,7 +224,7 @@ module SwitchmanInstJobs
224
224
  # Adapted from get_and_lock_next_available in delayed/backend/active_record.rb
225
225
  target_jobs = scope.limit(1000).lock('FOR UPDATE SKIP LOCKED')
226
226
 
227
- query = source_shard.activate(:delayed_jobs) do
227
+ query = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
228
228
  "WITH limited_jobs AS (#{target_jobs.to_sql}) " \
229
229
  "UPDATE #{::Delayed::Job.quoted_table_name} " \
230
230
  "SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)}, " \
@@ -233,7 +233,9 @@ module SwitchmanInstJobs
233
233
  "RETURNING #{::Delayed::Job.quoted_table_name}.*"
234
234
  end
235
235
 
236
- jobs = source_shard.activate(:delayed_jobs) { ::Delayed::Job.find_by_sql(query) }
236
+ jobs = source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
237
+ ::Delayed::Job.find_by_sql(query)
238
+ end
237
239
  new_jobs = jobs.map do |job|
238
240
  new_job = job.dup
239
241
  new_job.shard = target_shard
@@ -251,10 +253,10 @@ module SwitchmanInstJobs
251
253
  new_job
252
254
  end
253
255
  transaction_on([source_shard, target_shard]) do
254
- target_shard.activate(:delayed_jobs) do
256
+ target_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
255
257
  bulk_insert_jobs(new_jobs)
256
258
  end
257
- source_shard.activate(:delayed_jobs) do
259
+ source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
258
260
  ::Delayed::Job.delete(jobs)
259
261
  end
260
262
  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(:delayed_jobs) do
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(:delayed_jobs) do
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(:delayed_jobs) do
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[:delayed_jobs] &&
89
- categories[:primary] &&
90
- categories[:primary] != active_shards[:primary]
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[:delayed_jobs] =
93
- categories[:primary].delayed_jobs_shard
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
@@ -1,3 +1,3 @@
1
1
  module SwitchmanInstJobs
2
- VERSION = '3.1.2'.freeze
2
+ VERSION = '4.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman-inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.3
20
- - - "<"
19
+ version: '2.0'
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: 2.3.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.3
30
- - - "<"
29
+ version: '2.0'
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: 2.3.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: parallel
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,34 +50,40 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '5.2'
53
+ version: '6.1'
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: '6.1'
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: '5.2'
63
+ version: '6.1'
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '6.1'
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: '2.0'
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: '2.0'
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
@@ -107,19 +113,19 @@ dependencies:
107
113
  - !ruby/object:Gem::Version
108
114
  version: '0'
109
115
  - !ruby/object:Gem::Dependency
110
- name: imperium
116
+ name: diplomat
111
117
  requirement: !ruby/object:Gem::Requirement
112
118
  requirements:
113
- - - ">="
119
+ - - "~>"
114
120
  - !ruby/object:Gem::Version
115
- version: '0'
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: '0'
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,70 @@ dependencies:
182
188
  requirements:
183
189
  - - "~>"
184
190
  - !ruby/object:Gem::Version
185
- version: '3.6'
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.6'
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: '3.6'
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: '3.6'
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.3.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.3.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.8.1
233
+ version: '2.10'
228
234
  type: :development
229
235
  prerelease: false
230
236
  version_requirements: !ruby/object:Gem::Requirement
231
237
  requirements:
232
238
  - - "~>"
233
239
  - !ruby/object:Gem::Version
234
- version: 2.8.1
240
+ version: '2.10'
235
241
  - !ruby/object:Gem::Dependency
236
242
  name: simplecov
237
243
  requirement: !ruby/object:Gem::Requirement
238
244
  requirements:
239
245
  - - "~>"
240
246
  - !ruby/object:Gem::Version
241
- version: '0.18'
247
+ version: '0.21'
242
248
  type: :development
243
249
  prerelease: false
244
250
  version_requirements: !ruby/object:Gem::Requirement
245
251
  requirements:
246
252
  - - "~>"
247
253
  - !ruby/object:Gem::Version
248
- version: '0.18'
254
+ version: '0.21'
249
255
  - !ruby/object:Gem::Dependency
250
256
  name: wwtd
251
257
  requirement: !ruby/object:Gem::Requirement
@@ -260,7 +266,7 @@ dependencies:
260
266
  - - "~>"
261
267
  - !ruby/object:Gem::Version
262
268
  version: '1.4'
263
- description:
269
+ description:
264
270
  email:
265
271
  - bpetty@instructure.com
266
272
  executables: []
@@ -289,6 +295,7 @@ files:
289
295
  - db/migrate/20151210162949_improve_max_concurrent.rb
290
296
  - db/migrate/20161206323555_add_back_default_string_limits_jobs.rb
291
297
  - db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb
298
+ - db/migrate/20170308045401_add_delayed_jobs_shard_id_to_switchman_shards.rb
292
299
  - db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb
293
300
  - db/migrate/20190726154743_make_critical_columns_not_null.rb
294
301
  - db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb
@@ -298,6 +305,7 @@ files:
298
305
  - db/migrate/20200825011002_add_strand_order_override.rb
299
306
  - lib/switchman-inst-jobs.rb
300
307
  - lib/switchman_inst_jobs.rb
308
+ - lib/switchman_inst_jobs/active_record/connection_adapters/connection_pool.rb
301
309
  - lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb
302
310
  - lib/switchman_inst_jobs/active_record/migration.rb
303
311
  - lib/switchman_inst_jobs/delayed/backend/base.rb
@@ -320,7 +328,7 @@ homepage: https://github.com/instructure/switchman-inst-jobs
320
328
  licenses:
321
329
  - MIT
322
330
  metadata: {}
323
- post_install_message:
331
+ post_install_message:
324
332
  rdoc_options: []
325
333
  require_paths:
326
334
  - lib
@@ -328,15 +336,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
328
336
  requirements:
329
337
  - - ">="
330
338
  - !ruby/object:Gem::Version
331
- version: '2.5'
339
+ version: '2.6'
332
340
  required_rubygems_version: !ruby/object:Gem::Requirement
333
341
  requirements:
334
342
  - - ">="
335
343
  - !ruby/object:Gem::Version
336
344
  version: '0'
337
345
  requirements: []
338
- rubygems_version: 3.0.3
339
- signing_key:
346
+ rubygems_version: 3.2.15
347
+ signing_key:
340
348
  specification_version: 4
341
349
  summary: Switchman and Instructure Jobs compatibility gem.
342
350
  test_files: []