Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…nstalk
  • Loading branch information...
commit e166fcc6a5d002f550078b5739a366fdf3588b72 1 parent c48611b
David Brady authored

Showing 3 changed files with 49 additions and 0 deletions. Show diff stats Hide diff stats

  1. +29 0 bsget
  2. +19 0 bsput
  3. +1 0  whostheretard
29 bsget
... ... @@ -0,0 +1,29 @@
  1 +#!/usr/bin/env ruby
  2 +# bsget - get message from beanstalk queue
  3 +# Usage:
  4 +# bsput [-p port] [-h host] <message>
  5 +
  6 +require 'beanstalk-client'
  7 +require 'trollop'
  8 +
  9 +opts = Trollop.options do
  10 + opt :port, "port", :type => :integer, :default => 11300
  11 + opt :host, "host", :default => "localhost"
  12 + opt :tube, "tube to get message from", :default => "default"
  13 + opt :wait, "seconds to wait", :type => :integer, :default => nil
  14 + opt :peek, "do not delete message", :default => false
  15 +end
  16 +
  17 +bs = Beanstalk::Pool.new ["#{opts[:host]}:#{opts[:port]}"]
  18 +jobs = bs.stats_tube(opts[:tube])["current-jobs-ready"]
  19 +if jobs == 0
  20 + puts "No messages ready in tube '#{opts[:tube]}'"
  21 + exit 1
  22 +end
  23 +
  24 +bs.watch(opts[:tube])
  25 +msg = bs.reserve(opts[:wait])
  26 +puts msg.body
  27 +msg.delete unless opts[:peek]
  28 +
  29 +
19 bsput
... ... @@ -0,0 +1,19 @@
  1 +#!/usr/bin/env ruby
  2 +# bsput - put message on beanstalk queue
  3 +# Usage:
  4 +# bsput [-p port] [-h host] <message>
  5 +
  6 +require 'beanstalk-client'
  7 +require 'trollop'
  8 +
  9 +opts = Trollop.options do
  10 + opt :port, "port", :type => :integer, :default => 11300
  11 + opt :host, "host", :default => "localhost"
  12 + opt :tube, "tube to send message in", :default => "default"
  13 +end
  14 +bs = Beanstalk::Pool.new ["#{opts[:host]}:#{opts[:port]}"]
  15 +bs.use(opts[:tube])
  16 +msg = ARGV * ' '
  17 +puts "msg: #{msg}"
  18 +bs.put msg
  19 +
1  whostheretard
@@ -6,5 +6,6 @@
6 6 # whostheretard <file> <line>
7 7 NAME=$(git blame $1 | head -n $2 | tail -n 1 | ruby -ne 'puts $1 if $_=~/\((.*?) 20\d\d-\d\d-\d\d/')
8 8 echo $NAME is the retard
  9 +say $NAME is the weetawd
9 10
10 11

0 comments on commit e166fcc

Please sign in to comment.
Something went wrong with that request. Please try again.