Skip to content

Instantly share code, notes, and snippets.

@mrrooijen

mrrooijen/qu.rb Secret

Created July 12, 2012 00:44
Show Gist options
  • Save mrrooijen/15962d22d41562e03323 to your computer and use it in GitHub Desktop.
Save mrrooijen/15962d22d41562e03323 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module HireFire
module Macro
class Qu
class << self
# Counts the amount of jobs in the (provided) Qu queue(s).
#
# Example:
#
# HireFire::Macro::Qu.queue # all queues
# HireFire::Macro::Qu.queue("email") # only email queue
# HireFire::Macro::Qu.queue("audio", "video") # audio and video queues
#
# @param [Array] queues provide one or more queue names, or none for "all".
# @return [Integer] the number of jobs in the queue(s).
def queue(*queues)
queues = ::Qu.backend.queues if queues.empty?
total_queue_size = queues.flatten.inject(0) { |memo, queue| memo += ::Qu.backend.length(queue); memo }
# total_workers_working = ::Qu.backend.workers.select { |w| queues.include?(w.job["queue"]) }.count
total_queue_size #+ total_workers_working
end
end
end
end
end
# encoding: utf-8
module HireFire
module Macro
class Resque
class << self
# Counts the amount of jobs in the (provided) Resque queue(s).
#
# Example:
#
# HireFire::Macro::Resque.queue # all queues
# HireFire::Macro::Resque.queue("email") # only email queue
# HireFire::Macro::Resque.queue("audio", "video") # audio and video queues
#
# @param [Array] queues provide one or more queue names, or none for "all".
# @return [Integer] the number of jobs in the queue(s).
def queue(*queues)
if queues.empty?
::Resque.info[:pending].to_i + ::Resque.info[:working].to_i
else
queues = queues.flatten.map(&:to_s)
total_queue_size = queues.inject(0) { |memo, queue| memo += ::Resque.size(queue); memo }
total_workers_working = ::Resque.working.select { |w| queues.include?(w.job["queue"]) }.count
total_queue_size + total_workers_working
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment