switchman-inst-jobs 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/switchman_inst_jobs/jobs_migrator.rb +49 -34
- data/lib/switchman_inst_jobs/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a489d2a35d787be5492b4a5d710f1cc6560ad5c3d9f9ad965e0860338562d62
|
4
|
+
data.tar.gz: 88d1ff219ce44f9cb50846c631261ed792f4ce78a8ebde00ea5b08b3a172bf2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c0574bcb3b5e006072f67fcd6c6a4d892e8db919da73cf4edf4d8ac790c1481fd9777a6b6e6950934951efb647445ff756f59ee9ca663a5f5303588fa5a52b
|
7
|
+
data.tar.gz: b2ffe5cc363ab95d407d21a6c76e486dc9e40dc18d52ceabff9639e6408a33f392c33260a0d243720832e9c760ea8f9c55a941b6b0c31ba8fdae1328308bc5ee
|
@@ -39,16 +39,12 @@ module SwitchmanInstJobs
|
|
39
39
|
|
40
40
|
# Do the updates in batches and then just clear redis instead of clearing them one at a time
|
41
41
|
target_shards.each do |target_shard, shards|
|
42
|
-
|
42
|
+
updates = { delayed_jobs_shard_id: target_shard, block_stranded: true }
|
43
|
+
updates[:updated_at] = Time.zone.now if ::Switchman::Shard.column_names.include?('updated_at')
|
44
|
+
::Switchman::Shard.where(id: shards).update_all(updates)
|
43
45
|
end
|
44
46
|
clear_shard_cache
|
45
47
|
|
46
|
-
# Wait a little over the 60 second in-process shard cache clearing
|
47
|
-
# threshold to ensure that all new stranded jobs are now being
|
48
|
-
# enqueued with next_in_strand: false
|
49
|
-
Rails.logger.debug('Waiting for caches to clear')
|
50
|
-
sleep(65) unless @skip_cache_wait
|
51
|
-
|
52
48
|
::Switchman::Shard.clear_cache
|
53
49
|
# rubocop:disable Style/CombinableLoops
|
54
50
|
# We first migrate strands so that we can stop blocking strands before we migrate unstranded jobs
|
@@ -59,11 +55,33 @@ module SwitchmanInstJobs
|
|
59
55
|
source_shards.each do |s|
|
60
56
|
::Switchman::Shard.lookup(s).activate(:delayed_jobs) { migrate_everything }
|
61
57
|
end
|
58
|
+
ensure_unblock_stranded_for(shard_map.map(&:first))
|
62
59
|
# rubocop:enable Style/CombinableLoops
|
63
60
|
end
|
64
61
|
|
65
|
-
|
62
|
+
# if :migrate_strands ran on any shards that fell into scenario 1, then
|
63
|
+
# block_stranded never got flipped, so do that now.
|
64
|
+
def ensure_unblock_stranded_for(shards)
|
65
|
+
shards = ::Switchman::Shard.where(id: shards, block_stranded: true).to_a
|
66
|
+
return unless shards.any?
|
67
|
+
|
68
|
+
::Switchman::Shard.where(id: shards).update_all(block_stranded: false)
|
69
|
+
clear_shard_cache
|
70
|
+
|
71
|
+
# shards is an array of shard objects that is now stale cause block_stranded has been updated.
|
72
|
+
shards.map(&:delayed_jobs_shard).uniq.each do |dj_shard|
|
73
|
+
unblock_strands(dj_shard)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def clear_shard_cache(debug_message = nil)
|
66
78
|
::Switchman.cache.clear
|
79
|
+
Rails.logger.debug("Waiting for caches to clear #{debug_message}")
|
80
|
+
# Wait a little over the 60 second in-process shard cache clearing
|
81
|
+
# threshold to ensure that all new stranded jobs are now being
|
82
|
+
# enqueued with next_in_strand: false
|
83
|
+
# @skip_cache_wait is for spec usage only
|
84
|
+
sleep(65) unless @skip_cache_wait
|
67
85
|
end
|
68
86
|
|
69
87
|
# This method expects that all relevant shards already have block_stranded: true
|
@@ -125,7 +143,7 @@ module SwitchmanInstJobs
|
|
125
143
|
update_all(next_in_strand: false)
|
126
144
|
end
|
127
145
|
|
128
|
-
# 4) is taken care of here, by
|
146
|
+
# 4) is taken care of here, by leaving next_in_strand alone and
|
129
147
|
# it should execute on the new shard
|
130
148
|
batch_move_jobs(
|
131
149
|
target_shard: target_shard,
|
@@ -141,35 +159,32 @@ module SwitchmanInstJobs
|
|
141
159
|
updated = ::Switchman::Shard.where(id: source_shard_ids, block_stranded: true).
|
142
160
|
update_all(block_stranded: false)
|
143
161
|
# If this is being manually re-run for some reason to clean something up, don't wait for nothing to happen
|
144
|
-
unless updated.zero?
|
145
|
-
|
146
|
-
# Wait a little over the 60 second in-process shard cache clearing
|
147
|
-
# threshold to ensure that all new stranded jobs are now being
|
148
|
-
# enqueued with next_in_strand: false
|
149
|
-
Rails.logger.debug("Waiting for caches to clear (#{source_shard.id} -> #{target_shard.id})")
|
150
|
-
# for spec usage only
|
151
|
-
sleep(65) unless @skip_cache_wait
|
152
|
-
end
|
162
|
+
clear_shard_cache("(#{source_shard.id} -> #{target_shard.id})") unless updated.zero?
|
163
|
+
|
153
164
|
::Switchman::Shard.clear_cache
|
154
165
|
# At this time, let's unblock all the strands on the target shard that aren't being held by a blocker
|
155
166
|
# but actually could have run and we just didn't know it because we didn't know if they had jobs
|
156
167
|
# on the source shard
|
157
|
-
target_shard
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
168
|
+
unblock_strands(target_shard)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def unblock_strands(target_shard)
|
174
|
+
target_shard.activate(:delayed_jobs) do
|
175
|
+
loop do
|
176
|
+
# We only want to unlock stranded jobs where they don't belong to a blocked shard (if they *do* belong)
|
177
|
+
# to a blocked shard, they must be part of a concurrent jobs migration from a different source shard to
|
178
|
+
# this target shard, so we shouldn't unlock them yet. We only ever unlock one job here to keep the
|
179
|
+
# logic cleaner; if the job is n-stranded, after the first one runs, the trigger will unlock larger
|
180
|
+
# batches
|
181
|
+
break if ::Delayed::Job.where(id: ::Delayed::Job.select('DISTINCT ON (strand) id').
|
182
|
+
where.not(strand: nil).
|
183
|
+
where.not(shard_id: ::Switchman::Shard.where(block_stranded: true).pluck(:id)).where(
|
184
|
+
::Delayed::Job.select(1).from("#{::Delayed::Job.quoted_table_name} dj2").
|
185
|
+
where("dj2.next_in_strand = true OR dj2.source = 'JobsMigrator::StrandBlocker'").
|
186
|
+
where('dj2.strand = delayed_jobs.strand').arel.exists.not
|
187
|
+
).order(:strand, :strand_order_override, :id)).limit(500).update_all(next_in_strand: true).zero?
|
173
188
|
end
|
174
189
|
end
|
175
190
|
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.1.
|
4
|
+
version: 3.1.1
|
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:
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inst-jobs
|
@@ -260,7 +260,7 @@ dependencies:
|
|
260
260
|
- - "~>"
|
261
261
|
- !ruby/object:Gem::Version
|
262
262
|
version: '1.4'
|
263
|
-
description:
|
263
|
+
description:
|
264
264
|
email:
|
265
265
|
- bpetty@instructure.com
|
266
266
|
executables: []
|
@@ -319,7 +319,7 @@ homepage: https://github.com/instructure/switchman-inst-jobs
|
|
319
319
|
licenses:
|
320
320
|
- MIT
|
321
321
|
metadata: {}
|
322
|
-
post_install_message:
|
322
|
+
post_install_message:
|
323
323
|
rdoc_options: []
|
324
324
|
require_paths:
|
325
325
|
- lib
|
@@ -334,8 +334,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
334
|
- !ruby/object:Gem::Version
|
335
335
|
version: '0'
|
336
336
|
requirements: []
|
337
|
-
rubygems_version: 3.
|
338
|
-
signing_key:
|
337
|
+
rubygems_version: 3.1.4
|
338
|
+
signing_key:
|
339
339
|
specification_version: 4
|
340
340
|
summary: Switchman and Instructure Jobs compatibility gem.
|
341
341
|
test_files: []
|