inst-jobs-statsd 1.2.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inst-jobs-statsd.rb +0 -1
- data/lib/inst_jobs_statsd/default_tracking.rb +2 -2
- data/lib/inst_jobs_statsd/jobs_tracker.rb +8 -7
- data/lib/inst_jobs_statsd/naming.rb +1 -0
- data/lib/inst_jobs_statsd/version.rb +1 -1
- data/spec/gemfiles/42.gemfile +4 -3
- data/spec/gemfiles/51.gemfile +4 -3
- data/spec/gemfiles/60.gemfile +7 -0
- data/spec/inst_jobs_statsd/jobs_tracker_spec.rb +0 -1
- data/spec/inst_jobs_statsd/naming_spec.rb +12 -0
- data/spec/inst_jobs_statsd/stats/counters/failed_spec.rb +1 -1
- data/spec/inst_jobs_statsd/stats/counters/run_spec.rb +1 -1
- data/spec/inst_jobs_statsd/stats/periodic/failed_spec.rb +1 -1
- data/spec/inst_jobs_statsd/stats/periodic/queue_spec.rb +8 -8
- data/spec/inst_jobs_statsd/stats/periodic/run_spec.rb +4 -4
- data/spec/setup_test_db.rb +10 -2
- data/spec/spec_helper.rb +1 -3
- metadata +32 -42
- data/lib/inst_jobs_statsd/stats/counters/orphaned.rb +0 -34
- data/spec/gemfiles/50.gemfile +0 -7
- data/spec/inst_jobs_statsd/stats/counters/orphaned_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 792432d5ab16fd1e7cbf711085bb9067ff8e299526d2bd4be44fd35422d121a0
|
4
|
+
data.tar.gz: 3f1d439fc92c9dc54cea4001f56cce26c88bdc14b61cdf5c364b9f819dc9750c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4bfd22211bcec84a9caf210a68081b8a002a0011c1d9b232b4b4f0cd638506c98f601afce2f29274285761954fcab2ca143844cc195915f8b48d66376658639
|
7
|
+
data.tar.gz: 2113f8a57bfcb288688326f1f1569524a661998999ab85e5567289010b9c3a8ababd6648a375560218b9654a66525d9ffb995f1fa96d48c5f441bf740cc8ca7a
|
data/lib/inst-jobs-statsd.rb
CHANGED
@@ -10,7 +10,6 @@ require_relative 'inst_jobs_statsd/naming'
|
|
10
10
|
|
11
11
|
require_relative 'inst_jobs_statsd/stats/counters'
|
12
12
|
require_relative 'inst_jobs_statsd/stats/counters/failed'
|
13
|
-
require_relative 'inst_jobs_statsd/stats/counters/orphaned'
|
14
13
|
require_relative 'inst_jobs_statsd/stats/counters/run'
|
15
14
|
|
16
15
|
require_relative 'inst_jobs_statsd/stats/periodic'
|
@@ -7,8 +7,8 @@ module InstJobsStatsd
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def track_jobs
|
11
|
-
@jobs_tracker ||= JobsTracker.new
|
10
|
+
def track_jobs(enable_periodic_queries: true)
|
11
|
+
@jobs_tracker ||= JobsTracker.new(enable_periodic_queries: enable_periodic_queries)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module InstJobsStatsd
|
2
2
|
class JobsTracker
|
3
|
-
def self.track
|
4
|
-
@current_tracking = new
|
3
|
+
def self.track(enable_periodic_queries: true)
|
4
|
+
@current_tracking = new(enable_periodic_queries: enable_periodic_queries)
|
5
5
|
yield
|
6
6
|
tracking = @current_tracking
|
7
7
|
@current_tracking = nil
|
8
8
|
tracking
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize
|
11
|
+
def initialize(enable_periodic_queries: true)
|
12
12
|
Stats::Counters::Failed.enable
|
13
|
-
Stats::Counters::Orphaned.enable
|
14
13
|
Stats::Counters::Run.enable
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
if enable_periodic_queries
|
16
|
+
Stats::Periodic::Failed.enable
|
17
|
+
Stats::Periodic::Queue.enable
|
18
|
+
Stats::Periodic::Run.enable
|
19
|
+
end
|
19
20
|
|
20
21
|
Stats::Timing::Failed.enable
|
21
22
|
Stats::Timing::Perform.enable
|
data/spec/gemfiles/42.gemfile
CHANGED
@@ -2,6 +2,7 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec :path=>"../../"
|
4
4
|
|
5
|
-
gem "rails", "~> 4.2.
|
6
|
-
gem "
|
7
|
-
gem
|
5
|
+
gem "rails", "~> 4.2.11"
|
6
|
+
gem "pg", "~> 0.21.0"
|
7
|
+
gem "after_transaction_commit", "< 2"
|
8
|
+
gem "test_after_commit", "1.1.0"
|
data/spec/gemfiles/51.gemfile
CHANGED
@@ -2,6 +2,7 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec :path=>"../../"
|
4
4
|
|
5
|
-
gem "rails", "~> 5.1.
|
6
|
-
gem
|
7
|
-
gem
|
5
|
+
gem "rails", "~> 5.1.7"
|
6
|
+
gem "sinatra", "~> 2.0.8"
|
7
|
+
gem "sinatra-contrib", "~> 2.0.8"
|
8
|
+
gem "sprockets", "~> 3.7" # 4.0+ requires Ruby 2.5
|
@@ -13,7 +13,6 @@ RSpec.describe InstJobsStatsd::JobsTracker do
|
|
13
13
|
describe '.initialize' do
|
14
14
|
it 'enables everything' do
|
15
15
|
expect(InstJobsStatsd::Stats::Counters::Failed).to receive(:enable)
|
16
|
-
expect(InstJobsStatsd::Stats::Counters::Orphaned).to receive(:enable)
|
17
16
|
expect(InstJobsStatsd::Stats::Counters::Run).to receive(:enable)
|
18
17
|
|
19
18
|
expect(InstJobsStatsd::Stats::Periodic::Failed).to receive(:enable)
|
@@ -40,5 +40,17 @@ RSpec.describe InstJobsStatsd::Naming do
|
|
40
40
|
it { should include 'delayedjob.wut.region_name' }
|
41
41
|
it { should include 'delayedjob.wut.region_name.tag.a_tag_name' }
|
42
42
|
end
|
43
|
+
|
44
|
+
describe '.dd_job_tags' do
|
45
|
+
it 'works' do
|
46
|
+
job = double(tag: 'Account.run_reports_later', shard: double(id: 101), strand: 'special')
|
47
|
+
expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq({ tag: 'Account.run_reports_later', jobshard: 101})
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'properly munges job tags' do
|
51
|
+
job = double(tag: 'Quizzes::Quiz#do_something', strand: nil)
|
52
|
+
expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq({ tag: 'Quizzes-Quiz.do_something'})
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
@@ -13,7 +13,7 @@ RSpec.describe InstJobsStatsd::Stats::Counters::Failed do
|
|
13
13
|
.with(array_including(/\.failed$/), 1, 1, { short_stat: :failed, tags: {} })
|
14
14
|
|
15
15
|
InstJobsStatsd::Stats::Counters::Failed.enable_failed_count
|
16
|
-
x.
|
16
|
+
x.delay.perform
|
17
17
|
Delayed::Job.first.fail!
|
18
18
|
end
|
19
19
|
end
|
@@ -18,12 +18,12 @@ RSpec.describe InstJobsStatsd::Stats::Periodic::Queue do
|
|
18
18
|
before do
|
19
19
|
InstJobsStatsd::Stats::Periodic::Queue.enable_queue_depth
|
20
20
|
|
21
|
-
x.
|
21
|
+
x.delay.perform
|
22
22
|
Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
|
23
23
|
|
24
|
-
x.
|
25
|
-
x.
|
26
|
-
x.
|
24
|
+
x.delay.perform
|
25
|
+
x.delay(run_at: now + 1.minute).perform
|
26
|
+
x.delay(run_at: now + 10.minutes).perform
|
27
27
|
end
|
28
28
|
|
29
29
|
it do
|
@@ -56,12 +56,12 @@ RSpec.describe InstJobsStatsd::Stats::Periodic::Queue do
|
|
56
56
|
before do
|
57
57
|
InstJobsStatsd::Stats::Periodic::Queue.enable_queue_age
|
58
58
|
|
59
|
-
x.
|
59
|
+
x.delay.perform
|
60
60
|
Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
|
61
61
|
|
62
|
-
x.
|
63
|
-
x.
|
64
|
-
x.
|
62
|
+
x.delay.perform
|
63
|
+
x.delay(run_at: now + 1.minute).perform
|
64
|
+
x.delay(run_at: now + 10.minutes).perform
|
65
65
|
end
|
66
66
|
|
67
67
|
it do
|
@@ -18,8 +18,8 @@ RSpec.describe InstJobsStatsd::Stats::Periodic::Run do
|
|
18
18
|
before do
|
19
19
|
InstJobsStatsd::Stats::Periodic::Run.enable_run_depth
|
20
20
|
|
21
|
-
x.
|
22
|
-
x.
|
21
|
+
x.delay.perform
|
22
|
+
x.delay.perform
|
23
23
|
Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
|
24
24
|
end
|
25
25
|
|
@@ -37,8 +37,8 @@ RSpec.describe InstJobsStatsd::Stats::Periodic::Run do
|
|
37
37
|
before do
|
38
38
|
InstJobsStatsd::Stats::Periodic::Run.enable_run_age
|
39
39
|
|
40
|
-
x.
|
41
|
-
x.
|
40
|
+
x.delay.perform
|
41
|
+
x.delay.perform
|
42
42
|
Delayed::Job.first.update(locked_at: now, locked_by: 'test')
|
43
43
|
end
|
44
44
|
|
data/spec/setup_test_db.rb
CHANGED
@@ -35,7 +35,15 @@ ActiveRecord::Base.establish_connection(connection_config)
|
|
35
35
|
|
36
36
|
# Apply the migrations from the inst-jobs gem
|
37
37
|
inst_jobs_spec = Gem::Specification.find_by_name('inst-jobs')
|
38
|
-
|
39
|
-
ActiveRecord::
|
38
|
+
if ::Rails.version >= '6'
|
39
|
+
sm = ActiveRecord::Base.connection.schema_migration
|
40
|
+
migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/db/migrate', sm).migrations
|
41
|
+
ActiveRecord::Migrator.new(:up, migrations, sm).migrate
|
42
|
+
migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/spec/migrate', sm).migrations
|
43
|
+
ActiveRecord::Migrator.new(:up, migrations, sm).migrate
|
44
|
+
else
|
45
|
+
ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/db/migrate')
|
46
|
+
ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/spec/migrate')
|
47
|
+
end
|
40
48
|
Delayed::Backend::ActiveRecord::Job.reset_column_information
|
41
49
|
Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
if /^2\.
|
1
|
+
if /^2\.7/ =~ RUBY_VERSION && /51\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage to one build
|
2
2
|
require 'simplecov'
|
3
3
|
|
4
4
|
SimpleCov.start do
|
@@ -6,8 +6,6 @@ if /^2\.4/ =~ RUBY_VERSION && /50\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage t
|
|
6
6
|
add_filter 'spec'
|
7
7
|
track_files 'lib/**/*.rb'
|
8
8
|
end
|
9
|
-
|
10
|
-
SimpleCov.minimum_coverage(100)
|
11
9
|
end
|
12
10
|
|
13
11
|
require 'inst-jobs-statsd'
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Slade
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-26 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
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.13'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
19
|
+
version: '1.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.13'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
26
|
+
version: '1.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: inst_statsd
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,16 +90,16 @@ dependencies:
|
|
96
90
|
name: database_cleaner
|
97
91
|
requirement: !ruby/object:Gem::Requirement
|
98
92
|
requirements:
|
99
|
-
- -
|
93
|
+
- - "~>"
|
100
94
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
95
|
+
version: '1.7'
|
102
96
|
type: :development
|
103
97
|
prerelease: false
|
104
98
|
version_requirements: !ruby/object:Gem::Requirement
|
105
99
|
requirements:
|
106
|
-
- -
|
100
|
+
- - "~>"
|
107
101
|
- !ruby/object:Gem::Version
|
108
|
-
version: 1.
|
102
|
+
version: '1.7'
|
109
103
|
- !ruby/object:Gem::Dependency
|
110
104
|
name: factory_girl
|
111
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,16 +118,16 @@ dependencies:
|
|
124
118
|
name: pg
|
125
119
|
requirement: !ruby/object:Gem::Requirement
|
126
120
|
requirements:
|
127
|
-
- -
|
121
|
+
- - "~>"
|
128
122
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
123
|
+
version: '1.2'
|
130
124
|
type: :development
|
131
125
|
prerelease: false
|
132
126
|
version_requirements: !ruby/object:Gem::Requirement
|
133
127
|
requirements:
|
134
|
-
- -
|
128
|
+
- - "~>"
|
135
129
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
130
|
+
version: '1.2'
|
137
131
|
- !ruby/object:Gem::Dependency
|
138
132
|
name: pry
|
139
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,44 +160,44 @@ dependencies:
|
|
166
160
|
name: rspec
|
167
161
|
requirement: !ruby/object:Gem::Requirement
|
168
162
|
requirements:
|
169
|
-
- -
|
163
|
+
- - "~>"
|
170
164
|
- !ruby/object:Gem::Version
|
171
|
-
version: 3.
|
165
|
+
version: '3.9'
|
172
166
|
type: :development
|
173
167
|
prerelease: false
|
174
168
|
version_requirements: !ruby/object:Gem::Requirement
|
175
169
|
requirements:
|
176
|
-
- -
|
170
|
+
- - "~>"
|
177
171
|
- !ruby/object:Gem::Version
|
178
|
-
version: 3.
|
172
|
+
version: '3.9'
|
179
173
|
- !ruby/object:Gem::Dependency
|
180
174
|
name: rubocop
|
181
175
|
requirement: !ruby/object:Gem::Requirement
|
182
176
|
requirements:
|
183
177
|
- - "~>"
|
184
178
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
179
|
+
version: 0.48.0
|
186
180
|
type: :development
|
187
181
|
prerelease: false
|
188
182
|
version_requirements: !ruby/object:Gem::Requirement
|
189
183
|
requirements:
|
190
184
|
- - "~>"
|
191
185
|
- !ruby/object:Gem::Version
|
192
|
-
version:
|
186
|
+
version: 0.48.0
|
193
187
|
- !ruby/object:Gem::Dependency
|
194
188
|
name: simplecov
|
195
189
|
requirement: !ruby/object:Gem::Requirement
|
196
190
|
requirements:
|
197
191
|
- - "~>"
|
198
192
|
- !ruby/object:Gem::Version
|
199
|
-
version: '0.
|
193
|
+
version: '0.17'
|
200
194
|
type: :development
|
201
195
|
prerelease: false
|
202
196
|
version_requirements: !ruby/object:Gem::Requirement
|
203
197
|
requirements:
|
204
198
|
- - "~>"
|
205
199
|
- !ruby/object:Gem::Version
|
206
|
-
version: '0.
|
200
|
+
version: '0.17'
|
207
201
|
- !ruby/object:Gem::Dependency
|
208
202
|
name: timecop
|
209
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,15 +218,15 @@ dependencies:
|
|
224
218
|
requirements:
|
225
219
|
- - "~>"
|
226
220
|
- !ruby/object:Gem::Version
|
227
|
-
version: 1.
|
221
|
+
version: 1.4.0
|
228
222
|
type: :development
|
229
223
|
prerelease: false
|
230
224
|
version_requirements: !ruby/object:Gem::Requirement
|
231
225
|
requirements:
|
232
226
|
- - "~>"
|
233
227
|
- !ruby/object:Gem::Version
|
234
|
-
version: 1.
|
235
|
-
description:
|
228
|
+
version: 1.4.0
|
229
|
+
description:
|
236
230
|
email:
|
237
231
|
- jslade@instructure.com
|
238
232
|
executables: []
|
@@ -245,7 +239,6 @@ files:
|
|
245
239
|
- lib/inst_jobs_statsd/naming.rb
|
246
240
|
- lib/inst_jobs_statsd/stats/counters.rb
|
247
241
|
- lib/inst_jobs_statsd/stats/counters/failed.rb
|
248
|
-
- lib/inst_jobs_statsd/stats/counters/orphaned.rb
|
249
242
|
- lib/inst_jobs_statsd/stats/counters/run.rb
|
250
243
|
- lib/inst_jobs_statsd/stats/periodic.rb
|
251
244
|
- lib/inst_jobs_statsd/stats/periodic/failed.rb
|
@@ -259,12 +252,11 @@ files:
|
|
259
252
|
- spec/factories/jobs.rb
|
260
253
|
- spec/factories/workers.rb
|
261
254
|
- spec/gemfiles/42.gemfile
|
262
|
-
- spec/gemfiles/50.gemfile
|
263
255
|
- spec/gemfiles/51.gemfile
|
256
|
+
- spec/gemfiles/60.gemfile
|
264
257
|
- spec/inst_jobs_statsd/jobs_tracker_spec.rb
|
265
258
|
- spec/inst_jobs_statsd/naming_spec.rb
|
266
259
|
- spec/inst_jobs_statsd/stats/counters/failed_spec.rb
|
267
|
-
- spec/inst_jobs_statsd/stats/counters/orphaned_spec.rb
|
268
260
|
- spec/inst_jobs_statsd/stats/counters/run_spec.rb
|
269
261
|
- spec/inst_jobs_statsd/stats/periodic/failed_spec.rb
|
270
262
|
- spec/inst_jobs_statsd/stats/periodic/queue_spec.rb
|
@@ -282,7 +274,7 @@ homepage: https://github.com/instructure/inst-jobs-statsd
|
|
282
274
|
licenses:
|
283
275
|
- MIT
|
284
276
|
metadata: {}
|
285
|
-
post_install_message:
|
277
|
+
post_install_message:
|
286
278
|
rdoc_options: []
|
287
279
|
require_paths:
|
288
280
|
- lib
|
@@ -290,16 +282,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
290
282
|
requirements:
|
291
283
|
- - ">="
|
292
284
|
- !ruby/object:Gem::Version
|
293
|
-
version: '2.
|
285
|
+
version: '2.4'
|
294
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
295
287
|
requirements:
|
296
288
|
- - ">="
|
297
289
|
- !ruby/object:Gem::Version
|
298
290
|
version: '0'
|
299
291
|
requirements: []
|
300
|
-
|
301
|
-
|
302
|
-
signing_key:
|
292
|
+
rubygems_version: 3.1.4
|
293
|
+
signing_key:
|
303
294
|
specification_version: 4
|
304
295
|
summary: Stats reporting for inst-jobs
|
305
296
|
test_files:
|
@@ -313,14 +304,13 @@ test_files:
|
|
313
304
|
- spec/inst_jobs_statsd/stats/periodic_spec.rb
|
314
305
|
- spec/inst_jobs_statsd/stats/counters/failed_spec.rb
|
315
306
|
- spec/inst_jobs_statsd/stats/counters/run_spec.rb
|
316
|
-
- spec/inst_jobs_statsd/stats/counters/orphaned_spec.rb
|
317
307
|
- spec/inst_jobs_statsd/stats/timing_spec.rb
|
318
308
|
- spec/inst_jobs_statsd/jobs_tracker_spec.rb
|
319
309
|
- spec/spec_helper.rb
|
320
310
|
- spec/setup_test_db.rb
|
321
311
|
- spec/matchers.rb
|
312
|
+
- spec/gemfiles/60.gemfile
|
322
313
|
- spec/gemfiles/42.gemfile
|
323
|
-
- spec/gemfiles/50.gemfile
|
324
314
|
- spec/gemfiles/51.gemfile
|
325
315
|
- spec/factories/workers.rb
|
326
316
|
- spec/factories/jobs.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module InstJobsStatsd
|
2
|
-
module Stats
|
3
|
-
module Counters
|
4
|
-
module Orphaned
|
5
|
-
def self.enable
|
6
|
-
enable_orphaned_count
|
7
|
-
end
|
8
|
-
|
9
|
-
# The idea of the orphaned count: when a job finishes, if there
|
10
|
-
# are other jobs locked_by the *same* worker, they must have been
|
11
|
-
# orphaned, because they are not going to be picked up and run by
|
12
|
-
# the worker -- the work queue is designed to only have one job
|
13
|
-
# locked_by a worker at a time.
|
14
|
-
# This is based on the symptom seen in AMS-447, where mutliple
|
15
|
-
# rows of the jobs table can be (incorrectly) updated by the same
|
16
|
-
# query.
|
17
|
-
def self.enable_orphaned_count
|
18
|
-
Delayed::Worker.lifecycle.before(:perform) do |_worker, job|
|
19
|
-
report_orphaned_count(job)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.report_orphaned_count(job)
|
24
|
-
scope = Delayed::Job.where(
|
25
|
-
'locked_by = ? AND locked_at = ? AND id <> ?',
|
26
|
-
job.locked_by, job.locked_at, job.id
|
27
|
-
)
|
28
|
-
count = scope.count
|
29
|
-
Counters.report_count(:orphaned, count, job: job) unless count.zero?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/spec/gemfiles/50.gemfile
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
RSpec.describe InstJobsStatsd::Stats::Counters::Orphaned do
|
2
|
-
describe '.enable' do
|
3
|
-
it 'enables all the things' do
|
4
|
-
expect(InstJobsStatsd::Stats::Counters::Orphaned).to receive(:enable_orphaned_count)
|
5
|
-
InstJobsStatsd::Stats::Counters::Orphaned.enable
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '.report_orphaned_count' do
|
10
|
-
let(:x) { Struct.new(:perform).new(true) }
|
11
|
-
|
12
|
-
before do
|
13
|
-
Delayed::Worker.lifecycle.reset!
|
14
|
-
InstJobsStatsd::Stats::Counters::Orphaned.enable
|
15
|
-
|
16
|
-
4.times { x.send_later(:perform) }
|
17
|
-
Delayed::Job.order(:id).limit(3)
|
18
|
-
.update_all(locked_by: 'test', locked_at: Delayed::Job.db_time_now)
|
19
|
-
end
|
20
|
-
|
21
|
-
it do
|
22
|
-
expect(InstStatsd::Statsd).to receive(:count)
|
23
|
-
.with(array_including(/\.orphaned$/), 2, 1, { short_stat: anything, tags: {} })
|
24
|
-
Delayed::Worker.lifecycle.run_callbacks(:perform, nil, Delayed::Job.first) {}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|