Permalink
Browse files

`cmdstalk -all` watches all existing tubes.

  • Loading branch information...
pda committed May 7, 2014
1 parent b3d1729 commit ade6f6b01b058fac1f13835c4937f0baf61e53ed
Showing with 28 additions and 2 deletions.
  1. +2 −1 README.md
  2. +13 −0 bs/bs.go
  3. +4 −0 cli/options.go
  4. +9 −1 cmdstalk.go
View
@@ -41,6 +41,7 @@ Usage
cmdstalk -help
# Usage of ./cmdstalk:
# -address="127.0.0.1:11300": beanstalkd TCP address.
# -all=false: Listen to all tubes, instead of -tubes=...
# -cmd="": Command to run in worker.
# -tubes=[default]: Comma separated list of tubes.
@@ -73,11 +74,11 @@ file cmdstalk # cmdstalk: Mach-O 64-bit executable x86_64
TODO
----
* Default to watching all tubes via `list-tubes`.
* Retry limit for `exit(1)` releases.
* Retry back-off delay.
* Configurable concurrency per tube.
* Ship linux binary; GitHub releases?
* Poll for new tubes created after launch.
[beanstalkd]: http://kr.github.io/beanstalkd/
View
@@ -16,6 +16,19 @@ const (
DeadlineSoonDelay = 1 * time.Second
)
// Connect to beanstalkd and list tubes. Panic on error.
func MustConnectAndListTubes(address string) []string {
conn, err := beanstalk.Dial("tcp", address)
if err != nil {
panic(err)
}
tubes, err := conn.ListTubes()
if err != nil {
panic(err)
}
return tubes
}
// reserve-with-timeout until there's a job or something panic-worthy.
// Handles beanstalk.ErrTimeout by retrying immediately.
// Handles beanstalk.ErrDeadline by sleeping DeadlineSoonDelay before retry.
View
@@ -18,6 +18,9 @@ type Options struct {
// The beanstalkd TCP address.
Address string
// All == true means all tubes will be watched.
All bool
// The shell command to execute for each job.
Cmd string
@@ -45,6 +48,7 @@ func ParseFlags() (o Options, err error) {
o.Tubes = TubeList{"default"}
flag.StringVar(&o.Address, "address", "127.0.0.1:11300", "beanstalkd TCP address.")
flag.BoolVar(&o.All, "all", false, "Listen to all tubes, instead of -tubes=...")
flag.StringVar(&o.Cmd, "cmd", "", "Command to run in worker.")
flag.Var(&o.Tubes, "tubes", "Comma separated list of tubes.")
flag.Parse()
View
@@ -16,13 +16,21 @@ package main
import (
"github.com/99designs/cmdstalk/broker"
"github.com/99designs/cmdstalk/bs"
"github.com/99designs/cmdstalk/cli"
)
func main() {
opts := cli.MustParseFlags()
for _, tube := range opts.Tubes {
var tubes []string
if opts.All {
tubes = bs.MustConnectAndListTubes(opts.Address)
} else {
tubes = opts.Tubes
}
for _, tube := range tubes {
go func(tube string) {
b := broker.New(opts.Address, tube, opts.Cmd, nil)
b.Run(nil)

0 comments on commit ade6f6b

Please sign in to comment.