Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #32 from stitchfix/monitor-sizes-directly
Browse files Browse the repository at this point in the history
get sizes only for monitoring
  • Loading branch information
davetron5000 committed Feb 6, 2016
2 parents 0d983c2 + 866f259 commit 9251923
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ services:
- redis-server
rvm:
- 2.2.4
- 2.1.8
- 2.3.0
7 changes: 7 additions & 0 deletions app/models/resque_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def waiting
}
end

# Return the number of jobs waiting, by queue. Hash of queue_name => number of jobs waiting
def waiting_by_queue
Hash[@resque_data_store.queue_names.map { |queue_name|
[queue_name,@resque_data_store.queue_size(queue_name)]
}]
end

# Return all jobs that are currently running as an array of `RunningJob` instances
def jobs_running
worker_ids = Array(@resque_data_store.worker_ids)
Expand Down
2 changes: 1 addition & 1 deletion lib/monitoring/failed_job_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def check!
@resques.all.map { |resque_instance|
CheckResult.new(resque_name: resque_instance.name,
check_name: "resque.failed_jobs",
check_count: resque_instance.jobs_failed.size)
check_count: resque_instance.failed)
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/monitoring/queue_size_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Monitoring
class QueueSizeCheck < Monitoring::Checker
def check!
@resques.all.map { |resque_instance|
resque_instance.jobs_waiting.keys.sort.map { |queue_name|
jobs = resque_instance.jobs_waiting[queue_name]
waiting_by_queue = resque_instance.waiting_by_queue
waiting_by_queue.keys.sort.map { |queue_name|
CheckResult.new(resque_name: resque_instance.name,
scope: queue_name,
check_name: "resque.queue_size",
check_count: jobs.size)
check_count: waiting_by_queue[queue_name])
}
}.flatten
end
Expand Down
7 changes: 7 additions & 0 deletions test/models/resque_instance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def test_waiting
assert_equal 7,create_test_instance.waiting
end

def test_waiting_by_queue
waiting = create_test_instance.waiting_by_queue

assert_equal 2,waiting["bar"]
assert_equal 5,waiting["foo"]
end

def test_retry_job
resque_data_store = fake_resque_data_store
instance = create_test_instance(resque_data_store: resque_data_store)
Expand Down

0 comments on commit 9251923

Please sign in to comment.