summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-14 13:34:19 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-14 13:34:19 +0000
commit4a04335d45c35e9e8ea63b9ae93666510c0954a9 (patch)
tree9e306024ba97ea4e8319e092c35e9c80bc3f39b7
parentf03fbe8f961b9f6bd43315cfd9233fa105603c31 (diff)
Removed the flushing-action from custodian-dequeue and added it to the
new helper tool
-rwxr-xr-xbin/custodian-dequeue33
-rwxr-xr-xbin/custodian-queue140
2 files changed, 140 insertions, 33 deletions
diff --git a/bin/custodian-dequeue b/bin/custodian-dequeue
index a02a75c..49ed052 100755
--- a/bin/custodian-dequeue
+++ b/bin/custodian-dequeue
@@ -6,7 +6,6 @@
# SYNOPSIS
# custodian-dequeue [ -h | --help ]
# [ -m | --manual]
-# [ -f | --flush ]
# [ -l | --logfile FILE]
# [ -S | --server 1.2.3.4:123 ]
# [ -s | --single ]
@@ -18,8 +17,6 @@
#
# -m, --manual Show this manual, and exit.
#
-# -f, --flush Flush the queue, removing all jobs.
-#
# -l, --logfile Specify the path to the logfile to run.
#
# -S, --server Specify the host:port for the beanstalkd queue.
@@ -199,26 +196,6 @@ class Custodian
puts msg if ( ENV['VERBOSE'] )
end
- #
- # Flush the queue.
- #
- def flush_queue!
-
- log_message( "Flushing queue" )
-
- while( true )
- begin
- job = @queue.reserve(1)
- id = job.id
- log_message( "Deleted job #{id}" )
- job.delete
- rescue Beanstalk::TimedOut => ex
- log_message( "The queue is now empty" )
- return
- end
- end
- end
-
#
@@ -366,7 +343,6 @@ if __FILE__ == $0 then
begin
opts = GetoptLong.new(
- [ "--flush", "-f", GetoptLong::NO_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
[ "--manual", "-m", GetoptLong::NO_ARGUMENT ],
[ "--logfile", "-l", GetoptLong::REQUIRED_ARGUMENT ],
@@ -379,8 +355,6 @@ if __FILE__ == $0 then
case opt
when "--verbose":
ENV["VERBOSE"] = "1"
- when "--flush":
- ENV["FLUSH"] = "1"
when "--logfile":
$LOGFILE = arg
when "--repeat":
@@ -436,13 +410,6 @@ if __FILE__ == $0 then
#
worker = Custodian.new( $SERVER, $LOGFILE )
- #
- # Are we flushing the queue?
- #
- if ( ENV['FLUSH'] )
- worker.flush_queue!
- exit(0)
- end
#
# Single step?
diff --git a/bin/custodian-queue b/bin/custodian-queue
new file mode 100755
index 0000000..7eaa182
--- /dev/null
+++ b/bin/custodian-queue
@@ -0,0 +1,140 @@
+#!/usr/bin/ruby1.8
+#
+# NAME
+# custodian-queue - Work with the queue.
+#
+# SYNOPSIS
+# custodian-queu [ -h | --help ]
+# [ -m | --manual]
+# [ -f | --flush ]
+# [ -s | --stats]
+# [ -S | --server 1.2.3.4:123 ]
+#
+# OPTIONS
+#
+# -h, --help Show a help message, and exit.
+#
+# -m, --manual Show this manual, and exit.
+#
+# -f, --flush Flush the queue, removing all jobs.
+#
+# -s, --stats Show the pending jobs.
+#
+# -S, --server Specify the host:port for the beanstalkd queue.
+#
+#
+# ABOUT
+#
+# This tool is designed to inspect the beanstalkd queue.
+#
+#
+# AUTHOR
+#
+# Steve Kemp <steve@bytemark.co.uk>
+#
+
+
+
+require 'beanstalk-client'
+require 'getoptlong'
+
+
+
+
+#
+# Entry-point to our code.
+#
+if __FILE__ == $0 then
+
+ $SERVER = "127.0.0.1:11300"
+ $FLUSH = false
+ $STATS = false
+ $help = false
+ $manual = false
+
+ begin
+ opts = GetoptLong.new(
+ [ "--flush", "-f", GetoptLong::NO_ARGUMENT ],
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
+ [ "--manual", "-m", GetoptLong::NO_ARGUMENT ],
+ [ "--server", "-S", GetoptLong::REQUIRED_ARGUMENT ],
+ [ "--stats", "-s", GetoptLong::NO_ARGUMENT ]
+ )
+ opts.each do |opt, arg|
+ case opt
+ when "--stats":
+ $STATS = true
+ when "--flush":
+ $FLUSH = true
+ when "--server":
+ $SERVER = arg
+ when "--help":
+ $help = true
+ when "--manual":
+ $manual = true
+ end
+ end
+ rescue StandardError => ex
+ puts "Option parsing failed: #{ex.to_s}"
+ exit
+ end
+
+ #
+ # CAUTION! Here be quality kode.
+ #
+ if $manual or $help
+
+ # Open the file, stripping the shebang line
+ lines = File.open(__FILE__){|fh| fh.readlines}[1..-1]
+
+ found_synopsis = false
+
+ lines.each do |line|
+
+ line.chomp!
+ break if line.empty?
+
+ if $help and !found_synopsis
+ found_synopsis = (line =~ /^#\s+SYNOPSIS\s*$/)
+ next
+ end
+
+ puts line[2..-1].to_s
+
+ break if $help and found_synopsis and line =~ /^#\s*$/
+
+ end
+
+ exit 0
+ end
+
+ #
+ # Create the object
+ #
+ queue = Beanstalk::Pool.new([$SERVER])
+
+ #
+ # Showing stats?
+ #
+ if ( $STATS )
+ stats = queue.stats()
+ puts "There are #{stats['current-jobs-ready'] || 0} jobs pending."
+ exit( 0 )
+ end
+
+ #
+ # Are we flushing the queue?
+ #
+ if ( $FLUSH )
+ while( true )
+ begin
+ job = queue.reserve(1)
+ job.delete
+ rescue Beanstalk::TimedOut => ex
+ exit( 0 )
+ end
+ end
+ end
+
+
+end