roqua-support 0.1.28 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ded93f48de2dee044fe41d2803a89e9c789d1bde
4
- data.tar.gz: 42667e78929fc8f4e50ca8de5b36183e7074db4c
3
+ metadata.gz: 37d547c0a869c2c0e2a9ada0c1c81da42dd45633
4
+ data.tar.gz: 84acc128fb9a4dee25dd1c8e0e6109491db3976b
5
5
  SHA512:
6
- metadata.gz: 891b4c42815fc0c3dd06766a7a23de388acbfc17d4898d06b4177d3e1b329817793a0456ff3bbd54efeb248ebbf6b80f27b0073acf5ca11ea6fd51a3564ae7f6
7
- data.tar.gz: e2a34e8af41127a4924d7b51f75772dd31e9583c051f0ff0539d9eaad18727376c532254e121c3dc05839a633b06c3279c5b3cf7aca8274976520e66d4f08c1f
6
+ metadata.gz: cdc75baa084d6e000e2a2357f0ccd732c90dd228335110f7508a35066ec1680a410c614c32d9eb43ef73d4921521b0da739d3d0e764a9969353809915c917fa7
7
+ data.tar.gz: a074e16db2d3496285cdc293596fb6863e77089cbbd888f188f38037bb99c6917b158825ca9b375193c8addee071fe4061e63c1d57281e82437aac3ed7f8a1d6
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- roqua-support (0.1.28)
11
+ roqua-support (0.1.29)
12
12
  active_interaction (~> 3.0)
13
13
  activesupport (>= 3.2, < 6)
14
14
  naught (~> 1.0)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = '0.1.28'.freeze
3
+ VERSION = '0.1.29'.freeze
4
4
  end
5
5
  end
data/lib/roqua-support.rb CHANGED
@@ -5,6 +5,7 @@ require "roqua/support"
5
5
  module Roqua
6
6
  module Probes
7
7
  autoload :DelayedJobProbe, 'roqua/probes/delayed_job_probe'
8
+ autoload :MonitoringProbe, 'roqua/probes/monitoring_probe'
8
9
  autoload :SchedulingProbe, 'roqua/probes/scheduling_probe'
9
10
  end
10
11
 
@@ -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.28
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-10 00:00:00.000000000 Z
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