summaryrefslogtreecommitdiff
path: root/bin/custodian-queue
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-01-19 12:27:15 +0000
committerSteve Kemp <steve@steve.org.uk>2015-01-19 12:27:15 +0000
commit9a05949ea4d669cb192d3e1d04984e27b82b0a69 (patch)
tree1e6dadcb8baf8531f38d82b5fb2c33486c73829c /bin/custodian-queue
parent7991f9a5ffc4d09209bf0431c188106a88cd8258 (diff)
Updated to use our queue-abstraction.
This means we can queue/dequeue to either Redis or Beanstalkd.
Diffstat (limited to 'bin/custodian-queue')
-rwxr-xr-xbin/custodian-queue25
1 files changed, 10 insertions, 15 deletions
diff --git a/bin/custodian-queue b/bin/custodian-queue
index afcba2a..23f3841 100755
--- a/bin/custodian-queue
+++ b/bin/custodian-queue
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib/
#
# NAME
# custodian-queue - Work with the queue.
@@ -42,7 +42,6 @@
#
# Standard modules
#
-require 'beanstalk-client'
require 'getoptlong'
@@ -50,7 +49,7 @@ require 'getoptlong'
# Our code
#
require 'custodian/settings'
-
+require 'custodian/queue'
#
@@ -69,7 +68,6 @@ if __FILE__ == $0 then
#
settings = Custodian::Settings.instance()
$SERVER = settings.queue_server
- $QUEUE = settings.queue_name
begin
opts = GetoptLong.new(
@@ -78,7 +76,6 @@ if __FILE__ == $0 then
[ "--manual", "-m", GetoptLong::NO_ARGUMENT ],
[ "--monitor", "-M", GetoptLong::OPTIONAL_ARGUMENT ],
[ "--server", "-S", GetoptLong::REQUIRED_ARGUMENT ],
- [ "--queue", "-q", GetoptLong::REQUIRED_ARGUMENT ],
[ "--stats", "-s", GetoptLong::NO_ARGUMENT ]
)
opts.each do |opt, arg|
@@ -95,8 +92,6 @@ if __FILE__ == $0 then
$FLUSH = true
when "--server" then
$SERVER = arg
- when "--queue" then
- $QUEUE = arg
when "--help" then
$help = true
when "--manual" then
@@ -140,7 +135,7 @@ if __FILE__ == $0 then
#
# Create the queue object.
#
- queue = Beanstalk::Pool.new([$SERVER], $QUEUE )
+ queue = Custodian::QueueType.create( "redis" )
#
# Alerting on a queue that is too-full?
@@ -150,8 +145,7 @@ if __FILE__ == $0 then
#
# Find the number of jobs
#
- stats = queue.stats()
- jobs = stats['current-jobs-ready'] || 0
+ jobs = queue.size?
if ( jobs > $MONITOR )
exit 1
@@ -165,8 +159,8 @@ if __FILE__ == $0 then
# Showing stats?
#
if ( $STATS )
- stats = queue.stats()
- puts "There are #{stats['current-jobs-ready'] || 0} jobs pending."
+ jobs = queue.size?()
+ puts "There are #{jobs || 0} jobs pending."
exit( 0 )
end
@@ -176,10 +170,11 @@ if __FILE__ == $0 then
#
if ( $FLUSH )
count = 0
- while( true )
+ run = true
+ while( run )
begin
- job = queue.reserve(1)
- job.delete
+ job = queue.fetch(1)
+ exit(0) if ( job.nil? )
count += 1
rescue Beanstalk::TimedOut => ex
puts "Flushed #{count} pending jobs."