switchman-inst-jobs 1.6.0 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e4c1c0421945fc0c823b2b1e452801565ac1c3e5ad9aae77d52fd8a36d83d0d
4
- data.tar.gz: 87d5a191c8dd7c1918d1bae1d8b05ffdfee1146e462e9adab0869f2b2210f681
3
+ metadata.gz: '08102eee5c1da6d032170565b624d61f90fcbc1c6232e1214babda846c9674c9'
4
+ data.tar.gz: 5f9c75d442f40b706dff2a45bfab8dc99ff8599470c096bbea594f1a763d7640
5
5
  SHA512:
6
- metadata.gz: a6c0abc940a6f4a7dc73923e9e020b853f23d29551bb19efa67338ae1e0da0af9065cde8f6a9f60e212f9514dd95c73b242512f1e21e53147601ff7f8cde30c1
7
- data.tar.gz: 4caad338666dcfbb83967c007a28443a45f86aa813b8fa4f8d81f6354beb9e9f3b68ae7b4118afa5d40c6e2da77e34f7982c8e28a6c1de2e9cdcc99942acd2c4
6
+ metadata.gz: 9118a73e2a47f1e6083737f967cc298674b8884c8cc23c9d16efff9e087951d63e54129f51a1c5595f2ec4cadb4332208a2a0262e7992b5777c39ac08ae8efa1
7
+ data.tar.gz: 791c382a9fbb141dc0e2f763b936d953bbd575ac01fc869a652628992c93b47c3cf93b590d95bd7867698c9410cbb278932ed1404e1e6d9f582cf00825cda8b0
@@ -25,8 +25,8 @@ module SwitchmanInstJobs
25
25
  ::Object.include Delayed::MessageSending
26
26
  end
27
27
 
28
- def self.initialize_shackles
29
- ::Shackles.singleton_class.prepend Shackles::ClassMethods
28
+ def self.initialize_guard_rail
29
+ ::GuardRail.singleton_class.prepend GuardRail::ClassMethods
30
30
  end
31
31
 
32
32
  def self.initialize_switchman
@@ -44,9 +44,9 @@ require 'switchman_inst_jobs/delayed/pool'
44
44
  require 'switchman_inst_jobs/delayed/worker'
45
45
  require 'switchman_inst_jobs/delayed/worker/health_check'
46
46
  require 'switchman_inst_jobs/engine'
47
+ require 'switchman_inst_jobs/guard_rail'
47
48
  require 'switchman_inst_jobs/jobs_migrator'
48
49
  require 'switchman_inst_jobs/new_relic'
49
- require 'switchman_inst_jobs/shackles'
50
50
  require 'switchman_inst_jobs/switchman/database_server'
51
51
  require 'switchman_inst_jobs/switchman/default_shard'
52
52
  require 'switchman_inst_jobs/switchman/shard'
@@ -12,13 +12,13 @@ module SwitchmanInstJobs
12
12
  module Backend
13
13
  module Base
14
14
  module ClassMethods
15
- def enqueue(object, options = {})
15
+ def enqueue(object, **options)
16
16
  ::Switchman::Shard.periodic_clear_shard_cache
17
17
  current_shard = ::Switchman::Shard.current
18
18
  enqueue_options = options.merge(
19
19
  current_shard: current_shard
20
20
  )
21
- enqueue_job = -> { ::Shackles.activate(:master) { super(object, enqueue_options) } }
21
+ enqueue_job = -> { ::GuardRail.activate(:master) { 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
@@ -43,8 +43,8 @@ module SwitchmanInstJobs
43
43
  end
44
44
 
45
45
  def configured_shard_ids
46
- (::Delayed::Settings.worker_config.try(:[], 'workers') || [])
47
- .map { |w| w['shard'] }.compact.uniq
46
+ (::Delayed::Settings.worker_config.try(:[], 'workers') || []).
47
+ map { |w| w['shard'] }.compact.uniq
48
48
  end
49
49
 
50
50
  def processes_locked_locally
@@ -1,8 +1,9 @@
1
1
  module SwitchmanInstJobs
2
2
  module Delayed
3
3
  module MessageSending
4
- def send_later_enqueue_args(method, _enqueue_args = {}, *args)
5
- return send(method, *args) if ::Switchman::DatabaseServer.creating_new_shard
4
+ def delay(sender: nil, synchronous: false, **enqueue_args)
5
+ sender ||= __calculate_sender_for_delay
6
+ synchronous ||= ::Switchman::DatabaseServer.creating_new_shard
6
7
 
7
8
  super
8
9
  end
@@ -19,7 +19,7 @@ module SwitchmanInstJobs
19
19
  end
20
20
 
21
21
  def reschedule_abandoned_jobs(call_super: false)
22
- shards = ::Switchman::Shard.delayed_jobs_shards
22
+ shards = ::Switchman::Shard.delayed_jobs_shards.to_a
23
23
  call_super = shards.first if shards.length == 1
24
24
  unless call_super == false
25
25
  call_super.activate(:delayed_jobs) do
@@ -32,9 +32,7 @@ module SwitchmanInstJobs
32
32
  singleton = <<~SINGLETON
33
33
  periodic: Delayed::Worker::HealthCheck.reschedule_abandoned_jobs:#{shard.id}
34
34
  SINGLETON
35
- send_later_enqueue_args(
36
- :reschedule_abandoned_jobs, { singleton: singleton }, call_super: shard
37
- )
35
+ delay(singleton: singleton).reschedule_abandoned_jobs(call_super: shard)
38
36
  end
39
37
  end
40
38
  end
@@ -34,8 +34,8 @@ module SwitchmanInstJobs
34
34
  end
35
35
  end
36
36
 
37
- initializer 'sharding.shackles', after: 'switchman.extend_shackles' do
38
- SwitchmanInstJobs.initialize_shackles
37
+ initializer 'sharding.guard_rail', after: 'switchman.extend_guard_rail' do
38
+ SwitchmanInstJobs.initialize_guard_rail
39
39
  end
40
40
 
41
41
  initializer 'sharding.switchman' do
@@ -1,5 +1,5 @@
1
1
  module SwitchmanInstJobs
2
- module Shackles
2
+ module GuardRail
3
3
  module ClassMethods
4
4
  def activate(env, &block)
5
5
  if ::ActiveRecord::Migration.open_migrations.positive?
@@ -95,7 +95,7 @@ module SwitchmanInstJobs
95
95
  first = this_strand_scope.where('locked_by IS NOT NULL').next_in_strand_order.lock.first
96
96
  if first
97
97
  first_job = ::Delayed::Job.create!(strand: strand, next_in_strand: false)
98
- first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, [0])
98
+ first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, args: [0])
99
99
  first_job.queue = first.queue
100
100
  first_job.tag = 'Kernel.sleep'
101
101
  first_job.source = 'JobsMigrator::StrandBlocker'
@@ -106,8 +106,8 @@ module SwitchmanInstJobs
106
106
  first_job.save!
107
107
  # the rest of 3) is taken care of here
108
108
  # make sure that all the jobs moved over are NOT next in strand
109
- ::Delayed::Job.where(next_in_strand: true, strand: strand, locked_by: nil)
110
- .update_all(next_in_strand: false)
109
+ ::Delayed::Job.where(next_in_strand: true, strand: strand, locked_by: nil).
110
+ update_all(next_in_strand: false)
111
111
  end
112
112
 
113
113
  # 4) is taken care of here, by leaveing next_in_strand alone and
@@ -136,10 +136,10 @@ module SwitchmanInstJobs
136
136
  # but actually could have run and we just didn't know it because we didn't know if they had jobs
137
137
  # on the source shard
138
138
  # rubocop:disable Layout/LineLength
139
- strands_to_unblock = shard_scope.where.not(source: 'JobsMigrator::StrandBlocker')
140
- .distinct
141
- .where("NOT EXISTS (SELECT 1 FROM #{::Delayed::Job.quoted_table_name} dj2 WHERE delayed_jobs.strand=dj2.strand AND next_in_strand)")
142
- .pluck(:strand)
139
+ strands_to_unblock = shard_scope.where.not(source: 'JobsMigrator::StrandBlocker').
140
+ distinct.
141
+ where("NOT EXISTS (SELECT 1 FROM #{::Delayed::Job.quoted_table_name} dj2 WHERE delayed_jobs.strand=dj2.strand AND next_in_strand)").
142
+ pluck(:strand)
143
143
  # rubocop:enable Layout/LineLength
144
144
  strands_to_unblock.each do |strand|
145
145
  Delayed::Job.where(strand: strand).next_in_strand_order.first.update_attribute(:next_in_strand, true)
@@ -11,7 +11,7 @@ module SwitchmanInstJobs
11
11
  # shard's delayed_jobs_shard
12
12
  if shard&.default?
13
13
  # first look for any shard that behaves like a jobs shard
14
- dj_shard ||= ::Switchman::Shard.delayed_jobs_shards.first
14
+ dj_shard ||= ::Switchman::Shard.delayed_jobs_shards.find(&:database_server)
15
15
  # we're really truly out of options, use the default shard itself
16
16
  dj_shard ||= shard
17
17
  end
@@ -28,9 +28,9 @@ module SwitchmanInstJobs
28
28
  return unless wait
29
29
 
30
30
  delayed_jobs_shard.activate(:delayed_jobs) do
31
- while ::Delayed::Job.where(shard_id: id)
32
- .where.not(locked_at: nil)
33
- .where.not(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY).exists?
31
+ while ::Delayed::Job.where(shard_id: id).
32
+ where.not(locked_at: nil).
33
+ where.not(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY).exists?
34
34
  sleep 10
35
35
  lock_jobs_for_hold
36
36
  end
@@ -41,9 +41,9 @@ module SwitchmanInstJobs
41
41
  self.jobs_held = false
42
42
  save! if changed?
43
43
  delayed_jobs_shard.activate(:delayed_jobs) do
44
- ::Delayed::Job.where(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY, shard_id: id)
45
- .in_batches(of: 10_000)
46
- .update_all(
44
+ ::Delayed::Job.where(locked_by: ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY, shard_id: id).
45
+ in_batches(of: 10_000).
46
+ update_all(
47
47
  locked_by: nil,
48
48
  locked_at: nil,
49
49
  attempts: 0,
@@ -111,32 +111,27 @@ module SwitchmanInstJobs
111
111
  end
112
112
 
113
113
  def delayed_jobs_shards
114
- unless instance_variable_defined?(:@delayed_jobs_shards)
115
- # re-entrancy protection
116
- @delayed_jobs_shards = begin
117
- shard_dj_shards = [] unless ::Switchman::Shard.columns_hash.key?('delayed_jobs_shard_id')
118
- shard_dj_shards ||= begin
119
- ::Switchman::Shard
120
- .where.not(delayed_jobs_shard_id: nil)
121
- .distinct
122
- .pluck(:delayed_jobs_shard_id)
123
- .map { |id| ::Switchman::Shard.lookup(id) }
124
- .compact
125
- end
126
- # set it temporarily, to avoid the default shard falling back to itself
127
- # if other shards are usable
128
- @delayed_jobs_shards = shard_dj_shards.uniq.sort
129
-
130
- db_dj_shards = ::Switchman::DatabaseServer.all.map do |db|
131
- next db.shards.to_a if db.config[:delayed_jobs_shard] == 'self'
132
-
133
- db.delayed_jobs_shard
134
- end.compact.flatten.uniq # yes, all three
135
-
136
- (db_dj_shards + shard_dj_shards).uniq.sort
137
- end
114
+ return none unless ::Switchman::Shard.columns_hash.key?('delayed_jobs_shard_id')
115
+
116
+ scope = ::Switchman::Shard.unscoped.
117
+ where(id: ::Switchman::Shard.unscoped.distinct.where.not(delayed_jobs_shard_id: nil).
118
+ select(:delayed_jobs_shard_id))
119
+ db_jobs_shards = ::Switchman::DatabaseServer.all.map { |db| db.config[:delayed_jobs_shard] }.uniq
120
+ db_jobs_shards.delete(nil)
121
+ has_self = db_jobs_shards.delete('self')
122
+ scope = scope.or(::Switchman::Shard.unscoped.where(id: db_jobs_shards)) unless db_jobs_shards.empty?
123
+
124
+ if has_self
125
+ self_dbs = ::Switchman::DatabaseServer.all.
126
+ select { |db| db.config[:delayed_jobs_shard] == 'self' }.map(&:id)
127
+ scope = scope.or(::Switchman::Shard.unscoped.
128
+ where(id: ::Switchman::Shard.unscoped.where(delayed_jobs_shard_id: nil, database_server_id: self_dbs).
129
+ select(:id)))
138
130
  end
139
- @delayed_jobs_shards
131
+ @jobs_scope_empty = !scope.exists? unless instance_variable_defined?(:@jobs_scope_empty)
132
+ return [::Switchman::Shard.default] if @jobs_scope_empty
133
+
134
+ ::Switchman::Shard.merge(scope)
140
135
  end
141
136
  end
142
137
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchmanInstJobs
2
- VERSION = '1.6.0'.freeze
2
+ VERSION = '3.0.3'.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: 1.6.0
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-15 00:00:00.000000000 Z
11
+ date: 2020-11-11 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: '0.16'
20
- - - "<"
19
+ version: '1.0'
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '0.17'
22
+ version: 1.0.3
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: '0.16'
30
- - - "<"
29
+ version: '1.0'
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0.17'
32
+ version: 1.0.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: parallel
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -68,22 +68,16 @@ dependencies:
68
68
  name: switchman
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: '1.16'
74
- - - "<"
71
+ - - "~>"
75
72
  - !ruby/object:Gem::Version
76
- version: '1.17'
73
+ version: '2.0'
77
74
  type: :runtime
78
75
  prerelease: false
79
76
  version_requirements: !ruby/object:Gem::Requirement
80
77
  requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '1.16'
84
- - - "<"
78
+ - - "~>"
85
79
  - !ruby/object:Gem::Version
86
- version: '1.17'
80
+ version: '2.0'
87
81
  - !ruby/object:Gem::Dependency
88
82
  name: bundler
89
83
  requirement: !ruby/object:Gem::Requirement
@@ -174,14 +168,14 @@ dependencies:
174
168
  requirements:
175
169
  - - "~>"
176
170
  - !ruby/object:Gem::Version
177
- version: '12'
171
+ version: '13'
178
172
  type: :development
179
173
  prerelease: false
180
174
  version_requirements: !ruby/object:Gem::Requirement
181
175
  requirements:
182
176
  - - "~>"
183
177
  - !ruby/object:Gem::Version
184
- version: '12'
178
+ version: '13'
185
179
  - !ruby/object:Gem::Dependency
186
180
  name: rspec
187
181
  requirement: !ruby/object:Gem::Requirement
@@ -312,9 +306,9 @@ files:
312
306
  - lib/switchman_inst_jobs/delayed/worker.rb
313
307
  - lib/switchman_inst_jobs/delayed/worker/health_check.rb
314
308
  - lib/switchman_inst_jobs/engine.rb
309
+ - lib/switchman_inst_jobs/guard_rail.rb
315
310
  - lib/switchman_inst_jobs/jobs_migrator.rb
316
311
  - lib/switchman_inst_jobs/new_relic.rb
317
- - lib/switchman_inst_jobs/shackles.rb
318
312
  - lib/switchman_inst_jobs/switchman/database_server.rb
319
313
  - lib/switchman_inst_jobs/switchman/default_shard.rb
320
314
  - lib/switchman_inst_jobs/switchman/shard.rb
@@ -333,14 +327,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
333
327
  requirements:
334
328
  - - ">="
335
329
  - !ruby/object:Gem::Version
336
- version: '2.4'
330
+ version: '2.5'
337
331
  required_rubygems_version: !ruby/object:Gem::Requirement
338
332
  requirements:
339
333
  - - ">="
340
334
  - !ruby/object:Gem::Version
341
335
  version: '0'
342
336
  requirements: []
343
- rubygems_version: 3.0.3
337
+ rubygems_version: 3.1.4
344
338
  signing_key:
345
339
  specification_version: 4
346
340
  summary: Switchman and Instructure Jobs compatibility gem.