Permalink
Browse files

Added bsput/bsget, cmdline utilities to put and get messages onto Bea…

…nstalk
  • Loading branch information...
1 parent c48611b commit e166fcc6a5d002f550078b5739a366fdf3588b72 @dbrady committed Mar 28, 2009
Showing with 49 additions and 0 deletions.
  1. +29 −0 bsget
  2. +19 −0 bsput
  3. +1 −0 whostheretard
View
29 bsget
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+# bsget - get message from beanstalk queue
+# Usage:
+# bsput [-p port] [-h host] <message>
+
+require 'beanstalk-client'
+require 'trollop'
+
+opts = Trollop.options do
+ opt :port, "port", :type => :integer, :default => 11300
+ opt :host, "host", :default => "localhost"
+ opt :tube, "tube to get message from", :default => "default"
+ opt :wait, "seconds to wait", :type => :integer, :default => nil
+ opt :peek, "do not delete message", :default => false
+end
+
+bs = Beanstalk::Pool.new ["#{opts[:host]}:#{opts[:port]}"]
+jobs = bs.stats_tube(opts[:tube])["current-jobs-ready"]
+if jobs == 0
+ puts "No messages ready in tube '#{opts[:tube]}'"
+ exit 1
+end
+
+bs.watch(opts[:tube])
+msg = bs.reserve(opts[:wait])
+puts msg.body
+msg.delete unless opts[:peek]
+
+
View
19 bsput
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# bsput - put message on beanstalk queue
+# Usage:
+# bsput [-p port] [-h host] <message>
+
+require 'beanstalk-client'
+require 'trollop'
+
+opts = Trollop.options do
+ opt :port, "port", :type => :integer, :default => 11300
+ opt :host, "host", :default => "localhost"
+ opt :tube, "tube to send message in", :default => "default"
+end
+bs = Beanstalk::Pool.new ["#{opts[:host]}:#{opts[:port]}"]
+bs.use(opts[:tube])
+msg = ARGV * ' '
+puts "msg: #{msg}"
+bs.put msg
+
View
1 whostheretard
@@ -6,5 +6,6 @@
# whostheretard <file> <line>
NAME=$(git blame $1 | head -n $2 | tail -n 1 | ruby -ne 'puts $1 if $_=~/\((.*?) 20\d\d-\d\d-\d\d/')
echo $NAME is the retard
+say $NAME is the weetawd

0 comments on commit e166fcc

Please sign in to comment.