switchman-inst-jobs 3.0.2 → 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: 711bf6fd7dfbea7baa7bf9f663264fdcfc37c3aa137d7b01f4c64985274dd045
4
- data.tar.gz: 24955492cd97b95fbf3a8ab38c989fc40e0355751ddb43474c3c77b4839cdc43
3
+ metadata.gz: '08102eee5c1da6d032170565b624d61f90fcbc1c6232e1214babda846c9674c9'
4
+ data.tar.gz: 5f9c75d442f40b706dff2a45bfab8dc99ff8599470c096bbea594f1a763d7640
5
5
  SHA512:
6
- metadata.gz: 8e498902747984003acc07838e7cc596cd06c1bc0e9d9f88d24fb01c2eeef8d952e47f1da8913b4bea759cb19dde0e5ee0b0cb1651cb2c07e9708a34cef4ecaf
7
- data.tar.gz: 547333f01e1ec2aad62221c76702c33ce07b67009f2b584e0187d152ded1c468637514c3e401c83389898a24386c6c72d74ffb1c7b2e7e5e6a3b50591a3ebfa6
6
+ metadata.gz: 9118a73e2a47f1e6083737f967cc298674b8884c8cc23c9d16efff9e087951d63e54129f51a1c5595f2ec4cadb4332208a2a0262e7992b5777c39ac08ae8efa1
7
+ data.tar.gz: 791c382a9fbb141dc0e2f763b936d953bbd575ac01fc869a652628992c93b47c3cf93b590d95bd7867698c9410cbb278932ed1404e1e6d9f582cf00825cda8b0
@@ -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
@@ -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
@@ -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 = '3.0.2'.freeze
2
+ VERSION = '3.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman-inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
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-10-30 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