From b14761b3c896650dcba882ddc2752085f5b31380 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 21 Nov 2012 14:05:53 +0000 Subject: Decouple the enqueuing from the parsing. --- bin/custodian-enqueue | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'bin/custodian-enqueue') diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue index 23df794..c9d9232 100755 --- a/bin/custodian-enqueue +++ b/bin/custodian-enqueue @@ -50,9 +50,11 @@ # -# Implementation of our parser. +# Modules we require # +require 'beanstalk-client' require 'custodian/parser' +require 'getoptlong' @@ -63,11 +65,13 @@ if __FILE__ == $0 then $help = false $manual = false + $SERVER = "127.0.0.1:11300" begin opts = GetoptLong.new( [ "--dump", "-d", GetoptLong::NO_ARGUMENT ], [ "--test", GetoptLong::NO_ARGUMENT ], + [ "--server", GetoptLong::REQUIRED_ARGUMENT ], [ "--file", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--manual","-m", GetoptLong::NO_ARGUMENT ], @@ -79,6 +83,8 @@ if __FILE__ == $0 then ENV["DUMP"] = "1" when "--test" then ENV["TEST"] = "1" + when "--server" then + $SERVER = arg when "--file" then ENV["FILE"] = arg when "--timeout" then @@ -125,6 +131,16 @@ if __FILE__ == $0 then end + # + # Connected to the server + # + queue = Beanstalk::Pool.new([$SERVER]) + if ( ! queue ) + puts "Failed to connect to beanstalk server: #{$SERVER}" + exit 1 + end + + # # Create the parser # @@ -138,9 +154,19 @@ if __FILE__ == $0 then end # - # Run + # Run the parser - and get callbacks when a new job is added. # - mon.parse_file() + mon.parse_file do |test| + + if ( ENV['TEST'] ) + # nop + elsif ( ENV['DUMP'] ) + puts test.to_json + else + queue.put( test.to_json ) + end + end + # # If there were errors then we'll not get this far. -- cgit v1.2.1