Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the number of tries configurable instead of hardcoded to 10 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const (
// TimeoutTries is the number of timeouts a job must reach before it is
// buried. Zero means never execute.
TimeoutTries = 1
)

var (
// ReleaseTries is the number of releases a job must reach before it is
// buried. Zero means never execute.
ReleaseTries = 10
ReleaseTries uint64 = 10
)

type Broker struct {
Expand Down
8 changes: 8 additions & 0 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Options struct {
// PerTube is the number of workers servicing each tube concurrently.
PerTube uint64

// Tries is the number of times that a job should be attempted before being burried
Tries uint64

// The beanstalkd tubes to watch.
Tubes TubeList
}
Expand Down Expand Up @@ -54,6 +57,7 @@ func ParseFlags() (o Options, err error) {
flag.BoolVar(&o.All, "all", false, "Listen to all tubes, instead of -tubes=...")
flag.StringVar(&o.Cmd, "cmd", "", "Command to run in worker.")
flag.Uint64Var(&o.PerTube, "per-tube", 1, "Number of workers per tube.")
flag.Uint64Var(&o.Tries, "tries", 10, "Number of times to attempt to execute a job.")
flag.Var(&o.Tubes, "tubes", "Comma separated list of tubes.")
flag.Parse()

Expand All @@ -73,6 +77,10 @@ func validateOptions(o Options) error {
msgs = append(msgs, "Address must not be empty.")
}

if o.Tries < 1 {
msgs = append(msgs, "Tries must be 1 or more.")
}

if len(msgs) == 0 {
return nil
} else {
Expand Down
2 changes: 2 additions & 0 deletions cmdstalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
func main() {
opts := cli.MustParseFlags()

broker.ReleaseTries = opts.Tries

bd := broker.NewBrokerDispatcher(opts.Address, opts.Cmd, opts.PerTube)

if opts.All {
Expand Down