switchman-inst-jobs 1.6.0 → 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.rb +3 -3
- data/lib/switchman_inst_jobs/delayed/backend/base.rb +4 -4
- data/lib/switchman_inst_jobs/delayed/message_sending.rb +3 -2
- data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +2 -4
- data/lib/switchman_inst_jobs/engine.rb +2 -2
- data/lib/switchman_inst_jobs/{shackles.rb → guard_rail.rb} +1 -1
- data/lib/switchman_inst_jobs/jobs_migrator.rb +7 -7
- 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 +19 -25
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
|
data/lib/switchman_inst_jobs.rb
CHANGED
@@ -25,8 +25,8 @@ module SwitchmanInstJobs
|
|
25
25
|
::Object.include Delayed::MessageSending
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.
|
29
|
-
::
|
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 = -> { ::
|
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
|
-
|
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
|
5
|
-
|
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
|
-
|
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.
|
38
|
-
SwitchmanInstJobs.
|
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
|
@@ -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
|
-
|
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,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman-inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
20
|
-
- - "
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
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
|
30
|
-
- - "
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
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: '
|
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: '
|
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: '
|
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: '
|
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.
|
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.
|
337
|
+
rubygems_version: 3.1.4
|
344
338
|
signing_key:
|
345
339
|
specification_version: 4
|
346
340
|
summary: Switchman and Instructure Jobs compatibility gem.
|