Skip to content

Commit

Permalink
feat: resque-status: oldest job work time
Browse files Browse the repository at this point in the history
  • Loading branch information
Napolskih committed Feb 16, 2016
1 parent 1cca357 commit 966f9e8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/resque-status
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require 'optparse'
require 'redis'
require 'resque'
require 'active_support/core_ext/hash/slice'
require 'active_support/time'

options = {}

Expand Down Expand Up @@ -47,6 +48,12 @@ key = options.fetch(:key, :pending).to_sym

if info.key?(key)
puts info[key]
elsif key == :oldest
# oldest job work time in seconds
workers = Resque.workers
jobs = workers.map(&:job)
worker_jobs = workers.zip(jobs).reject { |w, j| w.idle? || j['queue'].nil? }
puts worker_jobs.map { |_, job| (Time.now.utc - DateTime.strptime(job['run_at'] ,'%Y-%m-%dT%H:%M:%S').utc).to_i }.max
else
$stderr.puts "Unknown key. Should be one of the [#{info.keys.join(', ')}]"
end

0 comments on commit 966f9e8

Please sign in to comment.