roqua-support 0.1.28 → 0.1.29
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/Gemfile.lock +1 -1
- data/lib/roqua/probes/monitoring_probe.rb +27 -0
- data/lib/roqua-support/version.rb +1 -1
- data/lib/roqua-support.rb +1 -0
- data/spec/roqua/probes/monitoring_probe_spec.rb +64 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d547c0a869c2c0e2a9ada0c1c81da42dd45633
|
4
|
+
data.tar.gz: 84acc128fb9a4dee25dd1c8e0e6109491db3976b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc75baa084d6e000e2a2357f0ccd732c90dd228335110f7508a35066ec1680a410c614c32d9eb43ef73d4921521b0da739d3d0e764a9969353809915c917fa7
|
7
|
+
data.tar.gz: a074e16db2d3496285cdc293596fb6863e77089cbbd888f188f38037bb99c6917b158825ca9b375193c8addee071fe4061e63c1d57281e82437aac3ed7f8a1d6
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'base_probe'
|
2
|
+
|
3
|
+
module Roqua
|
4
|
+
module Probes
|
5
|
+
class MonitoringProbe
|
6
|
+
extend BaseProbe
|
7
|
+
|
8
|
+
def incomplete_jobs
|
9
|
+
Roqua::Scheduling::CronJob.where('completed_at IS NULL OR completed_at < next_run_at')
|
10
|
+
end
|
11
|
+
|
12
|
+
def longest_delay_in_minutes
|
13
|
+
delays = incomplete_jobs.pluck(:next_run_at).map do |next_run_at|
|
14
|
+
Time.now - next_run_at
|
15
|
+
end
|
16
|
+
|
17
|
+
longest_delay_in_seconds = ([0] + delays).max
|
18
|
+
|
19
|
+
(longest_delay_in_seconds / 1.minute).to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
Appsignal.set_gauge('scheduler_delay_in_minutes', longest_delay_in_minutes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/roqua-support.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'delayed_job_active_record'
|
3
|
+
require 'timecop'
|
4
|
+
|
5
|
+
require 'roqua/probes/delayed_job_probe'
|
6
|
+
|
7
|
+
describe Roqua::Probes::DelayedJobProbe do
|
8
|
+
before { Timecop.freeze }
|
9
|
+
after { Timecop.return }
|
10
|
+
subject(:probe) { Roqua::Probes::MonitoringProbe.new }
|
11
|
+
|
12
|
+
before do
|
13
|
+
Roqua::Scheduling::CronJob.delete_all
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'call' do
|
17
|
+
it 'sends data to AppSignal' do
|
18
|
+
expect(Appsignal).to receive(:set_gauge).with('scheduler_delay_in_minutes', 10)
|
19
|
+
expect(probe).to receive(:longest_delay_in_minutes).and_return(10)
|
20
|
+
probe.call
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'longest_delay' do
|
25
|
+
it 'returns 0 if there are no schedules' do
|
26
|
+
expect(probe.longest_delay_in_minutes).to eql(0)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'if there is a job that should have run 10 minutes ago' do
|
30
|
+
Roqua::Scheduling::CronJob.create!(
|
31
|
+
name: 'hourly', next_run_at: 10.minutes.ago
|
32
|
+
)
|
33
|
+
expect(probe.longest_delay_in_minutes).to eql(10)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'if there is a job that should have run 10 minutes ago and the previous job was completed 15 minutes ago' do
|
37
|
+
Roqua::Scheduling::CronJob.create!(
|
38
|
+
name: 'hourly', next_run_at: 10.minutes.ago, completed_at: 15.minutes.ago
|
39
|
+
)
|
40
|
+
expect(probe.longest_delay_in_minutes).to eql(10)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'if there is a job that should have run 10 minutes ago and was completed 5 minutes ago' do
|
44
|
+
Roqua::Scheduling::CronJob.create!(
|
45
|
+
name: 'hourly', next_run_at: 10.minutes.ago, completed_at: 5.minutes.ago
|
46
|
+
)
|
47
|
+
expect(probe.longest_delay_in_minutes).to eql(0)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'when there is a job in the future that was never completed' do
|
51
|
+
Roqua::Scheduling::CronJob.create!(
|
52
|
+
name: 'hourly', next_run_at: 3.minutes.from_now
|
53
|
+
)
|
54
|
+
expect(probe.longest_delay_in_minutes).to eql(0)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'when there is a job in the future that was completed' do
|
58
|
+
Roqua::Scheduling::CronJob.create!(
|
59
|
+
name: 'hourly', next_run_at: 3.minutes.from_now, completed_at: 1.minute.ago
|
60
|
+
)
|
61
|
+
expect(probe.longest_delay_in_minutes).to eql(0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roqua-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_interaction
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/roqua/core_ext/fixnum/clamp.rb
|
213
213
|
- lib/roqua/probes/base_probe.rb
|
214
214
|
- lib/roqua/probes/delayed_job_probe.rb
|
215
|
+
- lib/roqua/probes/monitoring_probe.rb
|
215
216
|
- lib/roqua/probes/scheduling_probe.rb
|
216
217
|
- lib/roqua/responders/active_interaction_aware_responder.rb
|
217
218
|
- lib/roqua/responders/api_errors_responder.rb
|
@@ -239,6 +240,7 @@ files:
|
|
239
240
|
- spec/roqua/core_ext/fabrication/singleton_spec.rb
|
240
241
|
- spec/roqua/core_ext/fixnum/clamp_spec.rb
|
241
242
|
- spec/roqua/probes/delayed_job_probe_spec.rb
|
243
|
+
- spec/roqua/probes/monitoring_probe_spec.rb
|
242
244
|
- spec/roqua/responders/active_interaction_aware_responder_spec.rb
|
243
245
|
- spec/roqua/responders/api_errors_responder_spec.rb
|
244
246
|
- spec/roqua/scheduling/scheduler_spec.rb
|
@@ -285,6 +287,7 @@ test_files:
|
|
285
287
|
- spec/roqua/core_ext/fabrication/singleton_spec.rb
|
286
288
|
- spec/roqua/core_ext/fixnum/clamp_spec.rb
|
287
289
|
- spec/roqua/probes/delayed_job_probe_spec.rb
|
290
|
+
- spec/roqua/probes/monitoring_probe_spec.rb
|
288
291
|
- spec/roqua/responders/active_interaction_aware_responder_spec.rb
|
289
292
|
- spec/roqua/responders/api_errors_responder_spec.rb
|
290
293
|
- spec/roqua/scheduling/scheduler_spec.rb
|