switchman-inst-jobs 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/switchman_inst_jobs/delayed/backend/base.rb +2 -2
- data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +1 -1
- data/lib/switchman_inst_jobs/jobs_migrator.rb +6 -6
- data/lib/switchman_inst_jobs/switchman/database_server.rb +1 -1
- data/lib/switchman_inst_jobs/switchman/shard.rb +26 -31
- data/lib/switchman_inst_jobs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08102eee5c1da6d032170565b624d61f90fcbc1c6232e1214babda846c9674c9'
|
4
|
+
data.tar.gz: 5f9c75d442f40b706dff2a45bfab8dc99ff8599470c096bbea594f1a763d7640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
.
|
141
|
-
|
142
|
-
|
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.
|
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
|
-
|
33
|
-
|
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
|
-
|
46
|
-
|
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
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
@
|
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
|
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.
|
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-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inst-jobs
|