delayed_job-monitor 0.0.3 → 0.1.0
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.
- data/VERSION +1 -1
- data/delayed_job-monitor.gemspec +20 -28
- data/lib/delayed_job/monitor.rb +92 -100
- metadata +10 -14
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/delayed_job-monitor.gemspec
CHANGED
@@ -1,49 +1,41 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.0
|
7
|
+
s.name = "delayed_job-monitor"
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Guterl"]
|
12
|
-
s.date =
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.email = %q{michael@diminishing.org}
|
12
|
+
s.date = "2011-12-30"
|
13
|
+
s.description = "A tool for monitoring the health of a delayed_job work queue"
|
14
|
+
s.email = "michael@diminishing.org"
|
16
15
|
s.executables = ["delayed_job_monitor"]
|
17
16
|
s.extra_rdoc_files = [
|
18
17
|
"LICENSE",
|
19
|
-
|
18
|
+
"README.rdoc"
|
20
19
|
]
|
21
20
|
s.files = [
|
22
21
|
".document",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"lib/delayed_job/monitor.rb",
|
31
|
-
"spec/delayed_job-monitor_spec.rb",
|
32
|
-
"spec/spec.opts",
|
33
|
-
"spec/spec_helper.rb"
|
34
|
-
]
|
35
|
-
s.homepage = %q{http://github.com/recruitmilitary/delayed_job-monitor}
|
36
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.7}
|
39
|
-
s.summary = %q{Monitor the health of your delayed_job work queue}
|
40
|
-
s.test_files = [
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bin/delayed_job_monitor",
|
27
|
+
"delayed_job-monitor.gemspec",
|
28
|
+
"lib/delayed_job/monitor.rb",
|
41
29
|
"spec/delayed_job-monitor_spec.rb",
|
42
|
-
|
30
|
+
"spec/spec.opts",
|
31
|
+
"spec/spec_helper.rb"
|
43
32
|
]
|
33
|
+
s.homepage = "http://github.com/recruitmilitary/delayed_job-monitor"
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = "1.8.10"
|
36
|
+
s.summary = "Monitor the health of your delayed_job work queue"
|
44
37
|
|
45
38
|
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
39
|
s.specification_version = 3
|
48
40
|
|
49
41
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/delayed_job/monitor.rb
CHANGED
@@ -1,64 +1,60 @@
|
|
1
1
|
require 'sequel'
|
2
2
|
require 'pony'
|
3
3
|
|
4
|
-
|
4
|
+
class Delayed::Job::Monitor
|
5
5
|
|
6
|
-
class
|
6
|
+
class << self
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def run(options)
|
13
|
-
Delayed::Job::Monitor.new(options).run
|
14
|
-
end
|
8
|
+
def run(options)
|
9
|
+
Delayed::Job::Monitor.new(options).run
|
10
|
+
end
|
15
11
|
|
16
|
-
|
12
|
+
attr_accessor :default_table_name
|
17
13
|
|
18
|
-
|
14
|
+
end
|
19
15
|
|
20
|
-
|
16
|
+
DEFAULT_TABLE_NAME = "delayed_jobs".freeze
|
21
17
|
|
22
|
-
|
18
|
+
self.default_table_name = DEFAULT_TABLE_NAME
|
23
19
|
|
24
|
-
|
20
|
+
attr_reader :table_name
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
DEFAULT_THRESHOLDS = {
|
23
|
+
:total_job_threshold => 50,
|
24
|
+
:failed_job_threshold => 5,
|
25
|
+
:scheduled_job_threshold => 50,
|
26
|
+
:waiting_job_threshold => 5,
|
27
|
+
:running_job_threshold => 10
|
28
|
+
}.freeze
|
33
29
|
|
34
|
-
|
30
|
+
THRESHOLD_ATTRIBUTES = DEFAULT_THRESHOLDS.keys
|
35
31
|
|
36
|
-
|
32
|
+
attr_accessor *THRESHOLD_ATTRIBUTES
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
def initialize(options)
|
35
|
+
@options = options
|
36
|
+
@db_options = @options[:database]
|
37
|
+
@table_name = @db_options.delete(:table_name) { Delayed::Job::Monitor.default_table_name }
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
# set thresholds, use default if not provided
|
40
|
+
DEFAULT_THRESHOLDS.each do |attribute, threshold|
|
41
|
+
send("#{attribute}=", options.delete(attribute) { threshold })
|
42
|
+
end
|
43
|
+
end
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
def run
|
46
|
+
alert if sick?
|
47
|
+
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
def alert
|
50
|
+
Pony.mail(:to => "it@recruitmilitary.com",
|
51
|
+
:from => "deploy@recruitmilitary.com",
|
52
|
+
:subject => "[Alert] DJ Queue",
|
53
|
+
:body => alert_body)
|
54
|
+
end
|
59
55
|
|
60
|
-
|
61
|
-
|
56
|
+
def alert_body
|
57
|
+
%Q{
|
62
58
|
Delayed::Job Summary
|
63
59
|
--------------------
|
64
60
|
|
@@ -68,66 +64,62 @@ Scheduled jobs:\t\t#{scheduled_jobs}
|
|
68
64
|
Waiting jobs:\t\t#{waiting_jobs}
|
69
65
|
Running jobs:\t\t#{running_jobs}
|
70
66
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
def running_jobs
|
106
|
-
@running_jobs ||= count(["locked_at IS NOT NULL"])
|
107
|
-
end
|
108
|
-
|
109
|
-
def failed_jobs
|
110
|
-
@failed_jobs ||= count(["(run_at > ? AND last_error IS NOT NULL) OR failed_at IS NOT NULL", Time.now])
|
111
|
-
end
|
112
|
-
|
113
|
-
def count(filter = nil)
|
114
|
-
if filter
|
115
|
-
delayed_jobs.filter(filter).count
|
116
|
-
else
|
117
|
-
delayed_jobs.count
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def delayed_jobs
|
122
|
-
@delayed_jobs ||= database[table_name.to_sym]
|
123
|
-
end
|
124
|
-
|
125
|
-
def database
|
126
|
-
@database ||= Sequel.connect(@db_options)
|
127
|
-
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def sick?
|
70
|
+
total_jobs >= total_job_threshold ||
|
71
|
+
failed_jobs >= failed_job_threshold ||
|
72
|
+
scheduled_jobs >= scheduled_job_threshold ||
|
73
|
+
waiting_jobs >= waiting_job_threshold ||
|
74
|
+
running_jobs >= running_job_threshold
|
75
|
+
end
|
76
|
+
|
77
|
+
def healthy?
|
78
|
+
!sick?
|
79
|
+
end
|
80
|
+
|
81
|
+
def reset
|
82
|
+
@total_jobs = nil
|
83
|
+
@scheduled_jobs = nil
|
84
|
+
@waiting_jobs = nil
|
85
|
+
@running_jobs = nil
|
86
|
+
@failed_jobs = nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def total_jobs
|
90
|
+
@total_jobs ||= count
|
91
|
+
end
|
92
|
+
|
93
|
+
def scheduled_jobs
|
94
|
+
@scheduled_jobs ||= count(["run_at > ? AND locked_at IS NULL AND attempts = 0", Time.now])
|
95
|
+
end
|
96
|
+
|
97
|
+
def waiting_jobs
|
98
|
+
@waiting_jobs ||= count(["run_at <= ? AND locked_at IS NULL AND attempts = 0", Time.now])
|
99
|
+
end
|
128
100
|
|
101
|
+
def running_jobs
|
102
|
+
@running_jobs ||= count(["locked_at IS NOT NULL"])
|
103
|
+
end
|
104
|
+
|
105
|
+
def failed_jobs
|
106
|
+
@failed_jobs ||= count(["(run_at > ? AND last_error IS NOT NULL) OR failed_at IS NOT NULL", Time.now])
|
107
|
+
end
|
108
|
+
|
109
|
+
def count(filter = nil)
|
110
|
+
if filter
|
111
|
+
delayed_jobs.filter(filter).count
|
112
|
+
else
|
113
|
+
delayed_jobs.count
|
129
114
|
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def delayed_jobs
|
118
|
+
@delayed_jobs ||= database[table_name.to_sym]
|
119
|
+
end
|
130
120
|
|
121
|
+
def database
|
122
|
+
@database ||= Sequel.connect(@db_options)
|
131
123
|
end
|
132
124
|
|
133
125
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Guterl
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable: delayed_job_monitor
|
18
|
+
date: 2011-12-30 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rspec
|
@@ -77,7 +76,6 @@ extra_rdoc_files:
|
|
77
76
|
- README.rdoc
|
78
77
|
files:
|
79
78
|
- .document
|
80
|
-
- .gitignore
|
81
79
|
- LICENSE
|
82
80
|
- README.rdoc
|
83
81
|
- Rakefile
|
@@ -88,13 +86,12 @@ files:
|
|
88
86
|
- spec/delayed_job-monitor_spec.rb
|
89
87
|
- spec/spec.opts
|
90
88
|
- spec/spec_helper.rb
|
91
|
-
has_rdoc: true
|
92
89
|
homepage: http://github.com/recruitmilitary/delayed_job-monitor
|
93
90
|
licenses: []
|
94
91
|
|
95
92
|
post_install_message:
|
96
|
-
rdoc_options:
|
97
|
-
|
93
|
+
rdoc_options: []
|
94
|
+
|
98
95
|
require_paths:
|
99
96
|
- lib
|
100
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -118,10 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
115
|
requirements: []
|
119
116
|
|
120
117
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.8.10
|
122
119
|
signing_key:
|
123
120
|
specification_version: 3
|
124
121
|
summary: Monitor the health of your delayed_job work queue
|
125
|
-
test_files:
|
126
|
-
|
127
|
-
- spec/spec_helper.rb
|
122
|
+
test_files: []
|
123
|
+
|