resque-monitoring 0.0.2 → 0.0.3

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: 2d4474513df0631b5b929ef66d105ea6953971f9
4
- data.tar.gz: c44bb8f0dd6b5f28e42be21e3c43d17e99085bae
3
+ metadata.gz: 4b20ecf9be0c45f0abf6fe82f48f69ae0441a07c
4
+ data.tar.gz: 673a2ffbb4a24f744a83c77b06391a5f7ca69cbb
5
5
  SHA512:
6
- metadata.gz: 7623cddc69d3172611e91bd74259a88e39931218e0880d4c7a0c4ade3d12e454d740711476945502d6f3bdaa1f36f9e2169c5cd6927f26a3fece1b43ee1b3f1f
7
- data.tar.gz: b79aa822cd86aa94b8a77a56207117cd1f9c4367328c4ea58434b904001d4c70867bd2d1aeec950ad80e1d3950874d1f5b8e273002b4e6b51d48df7e074fbd24
6
+ metadata.gz: d96a0ec708bac72f629d83017dc621c6f5d95c7f0c6986ee685c2d02c5b1d875868b4db9df369cc3cde25685346ad749ac25429910e297bb1062f4f2d4ceaaff
7
+ data.tar.gz: 51c4fa58a8bc6f90d9067260b1f4cd8a94087948b8f75c99f14b816cd936d08362a2d853084713644ef1a64e02158a3264fd9688acb48bd8a7a507ab1e95081d
@@ -3,6 +3,7 @@ require "resque/monitoring/version"
3
3
  module Resque
4
4
  module Monitoring
5
5
  require 'active_support/core_ext'
6
+ require 'resque/monitoring/status'
6
7
  require 'resque/monitoring/scheduler'
7
8
  end
8
9
  end
@@ -15,20 +15,34 @@ module Resque
15
15
  end
16
16
 
17
17
  def status
18
- return :ok if assert.call(last_execution.date)
19
- :error
18
+ last_execution_date = last_execution.date
19
+ return not_executed_yet unless last_execution_date.present?
20
+ return Status.ok if assert.call(last_execution_date)
21
+ executed_long_time_ago(last_execution_date)
20
22
  end
21
23
 
22
24
  private
25
+ def not_executed_yet
26
+ Status.error('not executed yet')
27
+ end
28
+
29
+ def executed_long_time_ago(last_execution_date)
30
+ Status.error("executed a long time ago, last execution: #{last_execution_date}")
31
+ end
32
+
23
33
  def assert
24
- @assert ||= Proc.new do |last_execution|
25
- last_execution >= DateTime.now - 15.minutes
26
- end
34
+ @assert ||= default_assert
27
35
  end
28
36
 
29
37
  def last_execution
30
38
  @last_execution ||= LastExecution.by(name)
31
39
  end
40
+
41
+ def default_assert
42
+ Proc.new do |last_execution|
43
+ last_execution >= DateTime.now - 15.minutes
44
+ end
45
+ end
32
46
  end
33
47
  end
34
48
  end
@@ -17,8 +17,7 @@ module Resque
17
17
 
18
18
  def date
19
19
  value = Resque.redis.get(key)
20
- return DateTime.iso8601(value) if value
21
- DateTime.now - 30.years
20
+ DateTime.iso8601(value) if value
22
21
  end
23
22
 
24
23
  private
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ class Status
4
+ attr_reader :name, :message
5
+ @status = {}
6
+
7
+ def self.ok
8
+ fetch(:ok, 'status.alive') { |callback| }
9
+ end
10
+
11
+ def self.error(message)
12
+ fetch(:error, message) do |callback|
13
+ callback.call(message)
14
+ end
15
+ end
16
+
17
+ def when_error(&callback)
18
+ @status_callback.call(callback)
19
+ end
20
+
21
+ private
22
+ def initialize(name, message, &status_callback)
23
+ @name = name
24
+ @message = message
25
+ @status_callback = status_callback
26
+ end
27
+
28
+ def self.fetch(status, message, &callback)
29
+ @status["#{status}#{message}"] ||= new(status, message, &callback)
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module Monitoring
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narciso Benigno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - lib/resque/monitoring/scheduler/last_execution.rb
91
91
  - lib/resque/monitoring/scheduler.rb
92
+ - lib/resque/monitoring/status.rb
92
93
  - lib/resque/monitoring/version.rb
93
94
  - lib/resque/monitoring.rb
94
95
  homepage: ''