From 7d90bf7fba34d586c25ed096b8a2fc0fdf311879 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 19 Jan 2015 12:27:15 +0000 Subject: Updated to use our queue-abstraction. This means we can queue/dequeue to either Redis or Beanstalkd. --- bin/custodian-dequeue | 7 ++----- bin/custodian-enqueue | 34 ++++++++-------------------------- bin/custodian-queue | 25 ++++++++++--------------- 3 files changed, 20 insertions(+), 46 deletions(-) (limited to 'bin') diff --git a/bin/custodian-dequeue b/bin/custodian-dequeue index 3072fbd..7a99186 100755 --- a/bin/custodian-dequeue +++ b/bin/custodian-dequeue @@ -53,6 +53,7 @@ require 'getoptlong' # Our code. # require 'custodian/settings' +require 'custodian/queue' require 'custodian/worker' @@ -71,7 +72,6 @@ if __FILE__ == $0 then # settings = Custodian::Settings.instance() $SERVER = settings.queue_server - $QUEUE = settings.queue_name $ALERTER = settings.alerter $LOGFILE = settings.log_file @@ -82,7 +82,6 @@ if __FILE__ == $0 then [ "--manual", "-m", GetoptLong::NO_ARGUMENT ], [ "--fail", "-f", GetoptLong::NO_ARGUMENT ], [ "--logfile", "-l", GetoptLong::REQUIRED_ARGUMENT ], - [ "--queue", "-q", GetoptLong::REQUIRED_ARGUMENT ], [ "--server", "-S", GetoptLong::REQUIRED_ARGUMENT ], [ "--alerter", "-a", GetoptLong::REQUIRED_ARGUMENT ], [ "--single", "-s", GetoptLong::NO_ARGUMENT ], @@ -96,8 +95,6 @@ if __FILE__ == $0 then $LOGFILE = arg when "--server" then $SERVER = arg - when "--queue" then - $QUEUE = arg when "--alerter" then $ALERTER = arg when "--single" then @@ -149,7 +146,7 @@ if __FILE__ == $0 then # # Create the object # - worker = Custodian::Worker.new( $SERVER, $QUEUE, $ALERTER, $LOGFILE, settings ) + worker = Custodian::Worker.new( $SERVER, $ALERTER, $LOGFILE, settings ) # diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue index a6b9828..20654c1 100755 --- a/bin/custodian-enqueue +++ b/bin/custodian-enqueue @@ -1,7 +1,7 @@ #!/usr/bin/ruby -Ilib/ # # NAME -# custodian-enqueue - Parse tests from a file and enqueue to beanstalkd. +# custodian-enqueue - Parse tests from a file and enqueue them. # # SYNOPSIS # custodian-enqueue [ -h | --help ] @@ -19,8 +19,6 @@ # # -d, --dump Dump the parsed tests to the console; don't insert in the queue. # -# -q, --queue Use the named beanstalkd tube. -# # --test Test the parsing of the given file, alert on errors. # # -f, --file FILE Parse the given configuration file. @@ -29,17 +27,15 @@ # # ABOUT # -# This tool reads a single configuration file and parses it into a +# This tool reads a single configuration file and parses it into a # series of network & protocol tests. These tests are then stored in -# a beanstalkd queue. +# a queue from which workers can retrieve and execute them. # -# The intention is that the tests will be pulled from the queue and -# executed by the companion program custodian-dequeue. The dequeing -# process may occur up numerous other hosts +# The dequeing process may occur up numerous other hosts # # CONFIGURATION FILE # -# The configuration file is 99% compatible with that used in the tool +# The configuration file is 99% compatible with that used in the tool # custodian replaces. # # @@ -53,13 +49,13 @@ # # Standard modules # -require 'beanstalk-client' require 'getoptlong' # # Our code. # require 'custodian/parser' +require 'custodian/queue' require 'custodian/settings' @@ -77,7 +73,6 @@ if __FILE__ == $0 then # settings = Custodian::Settings.instance() $SERVER = settings.queue_server - $QUEUE = settings.queue_name begin opts = GetoptLong.new( @@ -86,7 +81,6 @@ if __FILE__ == $0 then [ "--server", GetoptLong::REQUIRED_ARGUMENT ], [ "--file", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--queue", "-q", GetoptLong::REQUIRED_ARGUMENT ], [ "--manual","-m", GetoptLong::NO_ARGUMENT ] ) opts.each do |opt, arg| @@ -97,8 +91,6 @@ if __FILE__ == $0 then ENV["TEST"] = "1" when "--server" then $SERVER = arg - when "--queue" then - $QUEUE= arg when "--file" then ENV["FILE"] = arg when "--help" then @@ -146,7 +138,7 @@ if __FILE__ == $0 then # # Connected to the server # - queue = Beanstalk::Pool.new([$SERVER], $QUEUE ) + queue = Custodian::QueueType.create( "redis" ) if ( ! queue ) puts "Failed to connect to beanstalk server: #{$SERVER}" exit 1 @@ -178,17 +170,7 @@ if __FILE__ == $0 then elsif ( ENV['DUMP'] ) puts test else - - # priority of new job. - priority = 1000 - - # delay before putting into queue. - delay = 0 - - # time-to-remove: how long job.reserve() will live for. - ttr = 300 - - queue.put( test.to_s, priority, delay, ttr ) + queue.add( test.to_s ) end end 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." -- cgit v1.2.1