This repository has been archived by the owner on Mar 14, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from stitchfix/failed-jobs-by-class
stat failures by class
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'ostruct' | ||
module Monitoring | ||
class FailedJobByClassCheck < Monitoring::Checker | ||
def check! | ||
@resques.all.map { |resque_instance| | ||
by_class = resque_instance.jobs_failed.group_by { |job| job.payload["class"] || "NoClass" } | ||
by_class.keys.sort.map { |class_name| | ||
CheckResult.new(resque_name: resque_instance.name, | ||
check_name: "resque.failed_jobs", | ||
scope: class_name.parameterize, | ||
check_count: by_class[class_name].size) | ||
} | ||
}.flatten.compact | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
require 'quick_test_helper' | ||
require 'support/resque_helpers' | ||
require 'support/monitoring_helpers' | ||
require 'minitest/autorun' | ||
require 'resque' | ||
|
||
lib_require 'monitoring/checker' | ||
lib_require 'monitoring/check_result' | ||
lib_require 'monitoring/failed_job_by_class_check' | ||
|
||
rails_require 'models/resque_instance' | ||
rails_require 'models/job' | ||
rails_require 'models/failed_job' | ||
rails_require 'models/resques' | ||
|
||
module Monitoring | ||
end | ||
class Monitoring::FailedJobByClassCheckTest < MiniTest::Test | ||
include ResqueHelpers | ||
include MonitoringHelpers | ||
|
||
def setup_resques(test1: ["BazJob", nil], test2: ["FooJob","FooJob", "BarJob"]) | ||
Redis.new.flushall | ||
Resques.new([ | ||
add_failed_jobs(job_class_names: test1, resque_instance: resque_instance("test1",:resque)), | ||
add_failed_jobs(job_class_names: test2, resque_instance: resque_instance("test2",:resque2)), | ||
]) | ||
end | ||
|
||
def test_failed_jobs | ||
resques = setup_resques | ||
check = Monitoring::FailedJobByClassCheck.new(resques: resques) | ||
|
||
results = check.check! | ||
|
||
assert_check_result results[0], resque_name: "test1", scope: "bazjob", check_count: 1 | ||
assert_check_result results[1], resque_name: "test1", scope: "noclass", check_count: 1 | ||
assert_check_result results[2], resque_name: "test2", scope: "barjob", check_count: 1 | ||
assert_check_result results[3], resque_name: "test2", scope: "foojob", check_count: 2 | ||
end | ||
|
||
def test_no_failed_jobs | ||
resques = setup_resques(test1: [], test2: []) | ||
check = Monitoring::FailedJobByClassCheck.new(resques: resques) | ||
|
||
results = check.check! | ||
|
||
assert_equal 0,results.size | ||
end | ||
end |