delayed_job-monitor 0.0.2

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Michael Guterl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = delayed_job-monitor
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Michael Guterl. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "delayed_job-monitor"
8
+ gem.summary = %Q{Monitor the health of your delayed_job work queue}
9
+ gem.description = %Q{A tool for monitoring the health of a delayed_job work queue}
10
+ gem.email = "michael@diminishing.org"
11
+ gem.homepage = "http://github.com/recruitmilitary/delayed_job-monitor"
12
+ gem.authors = ["Michael Guterl"]
13
+ gem.add_development_dependency "rspec", ">= 1.3.0"
14
+ gem.add_dependency "sequel", "~> 3.12.1"
15
+ gem.add_dependency "pony", "~> 1.0.0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "delayed_job-monitor #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # assumes the cwd is a rails application
4
+
5
+ require 'yaml'
6
+ require 'delayed_job/monitor'
7
+
8
+ rails_env = ENV['RAILS_ENV'] || 'development'
9
+ configuration = YAML.load_file("config/database.yml")
10
+
11
+ Delayed::Job::Monitor.run(:database => configuration[rails_env])
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{delayed_job-monitor}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Guterl"]
12
+ s.date = %q{2010-06-23}
13
+ s.default_executable = %q{delayed_job_monitor}
14
+ s.description = %q{A tool for monitoring the health of a delayed_job work queue}
15
+ s.email = %q{michael@diminishing.org}
16
+ s.executables = ["delayed_job_monitor"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/delayed_job_monitor",
29
+ "delayed_job-monitor.gemspec",
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 = [
41
+ "spec/delayed_job-monitor_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
51
+ s.add_runtime_dependency(%q<sequel>, ["~> 3.12.1"])
52
+ s.add_runtime_dependency(%q<pony>, ["~> 1.0.0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
55
+ s.add_dependency(%q<sequel>, ["~> 3.12.1"])
56
+ s.add_dependency(%q<pony>, ["~> 1.0.0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
60
+ s.add_dependency(%q<sequel>, ["~> 3.12.1"])
61
+ s.add_dependency(%q<pony>, ["~> 1.0.0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,133 @@
1
+ require 'sequel'
2
+ require 'pony'
3
+
4
+ module Delayed
5
+
6
+ class Job
7
+
8
+ class Monitor
9
+
10
+ class << self
11
+
12
+ def run(options)
13
+ Delayed::Job::Monitor.new(options).run
14
+ end
15
+
16
+ attr_accessor :default_table_name
17
+
18
+ end
19
+
20
+ DEFAULT_TABLE_NAME = "delayed_jobs".freeze
21
+
22
+ self.default_table_name = DEFAULT_TABLE_NAME
23
+
24
+ attr_reader :table_name
25
+
26
+ DEFAULT_THRESHOLDS = {
27
+ :total_job_threshold => 50,
28
+ :failed_job_threshold => 5,
29
+ :scheduled_job_threshold => 50,
30
+ :waiting_job_threshold => 5,
31
+ :running_job_threshold => 10
32
+ }.freeze
33
+
34
+ THRESHOLD_ATTRIBUTES = DEFAULT_THRESHOLDS.keys
35
+
36
+ attr_accessor *THRESHOLD_ATTRIBUTES
37
+
38
+ def initialize(options)
39
+ @options = options
40
+ @db_options = @options[:database]
41
+ @table_name = @db_options.delete(:table_name) { Delayed::Job::Monitor.default_table_name }
42
+
43
+ # set thresholds, use default if not provided
44
+ DEFAULT_THRESHOLDS.each do |attribute, threshold|
45
+ send("#{attribute}=", options.delete(attribute) { threshold })
46
+ end
47
+ end
48
+
49
+ def run
50
+ alert if sick?
51
+ end
52
+
53
+ def alert
54
+ Pony.mail(:to => "it@recruitmilitary.com",
55
+ :from => "deploy@recruitmilitary.com",
56
+ :subject => "[Alert] DJ Queue",
57
+ :body => alert_body)
58
+ end
59
+
60
+ def alert_body
61
+ %Q{
62
+ Delayed::Job Summary
63
+ --------------------
64
+
65
+ Total jobs:\t\t#{total_jobs}
66
+ Failed jobs:\t\t#{failed_jobs}
67
+ Scheduled jobs:\t\t#{scheduled_jobs}
68
+ Waiting jobs:\t\t#{waiting_jobs}
69
+ Running jobs:\t\t#{running_jobs}
70
+ }
71
+ end
72
+
73
+ def sick?
74
+ total_jobs >= total_job_threshold ||
75
+ failed_jobs >= failed_job_threshold ||
76
+ scheduled_jobs >= scheduled_job_threshold ||
77
+ waiting_jobs >= waiting_job_threshold ||
78
+ running_jobs >= running_job_threshold
79
+ end
80
+
81
+ def healthy?
82
+ !sick?
83
+ end
84
+
85
+ def reset
86
+ @total_jobs = nil
87
+ @scheduled_jobs = nil
88
+ @waiting_jobs = nil
89
+ @running_jobs = nil
90
+ @failed_jobs = nil
91
+ end
92
+
93
+ def total_jobs
94
+ @total_jobs ||= count
95
+ end
96
+
97
+ def scheduled_jobs
98
+ @scheduled_jobs ||= count(["run_at > ? AND locked_at IS NULL AND attempts = 0", Time.now])
99
+ end
100
+
101
+ def waiting_jobs
102
+ @waiting_jobs ||= count(["run_at <= ? AND locked_at IS NULL AND attempts = 0", Time.now])
103
+ end
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(["failed_at IS NOT NULL"])
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
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "DelayedJobMonitor" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'delayed_job-monitor'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayed_job-monitor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Michael Guterl
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-23 00:00:00 -04:00
19
+ default_executable: delayed_job_monitor
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: sequel
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 53
46
+ segments:
47
+ - 3
48
+ - 12
49
+ - 1
50
+ version: 3.12.1
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: pony
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 0
66
+ version: 1.0.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: A tool for monitoring the health of a delayed_job work queue
70
+ email: michael@diminishing.org
71
+ executables:
72
+ - delayed_job_monitor
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - .gitignore
81
+ - LICENSE
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - bin/delayed_job_monitor
86
+ - delayed_job-monitor.gemspec
87
+ - lib/delayed_job/monitor.rb
88
+ - spec/delayed_job-monitor_spec.rb
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/recruitmilitary/delayed_job-monitor
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Monitor the health of your delayed_job work queue
125
+ test_files:
126
+ - spec/delayed_job-monitor_spec.rb
127
+ - spec/spec_helper.rb