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

parsing hostname from command line or env #37

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var (
exitOnComplete bool
isStrict bool
useNumber bool
hostname string
)

// Namespace returns the namespace flag for goworker. You
Expand Down Expand Up @@ -138,6 +139,9 @@ func init() {
flag.BoolVar(&exitOnComplete, "exit-on-complete", false, "exit when the queue is empty")

flag.BoolVar(&useNumber, "use-number", false, "use json.Number instead of float64 when decoding numbers in JSON. will default to true soon")

hostname = os.Getenv("HOSTNAME")
flag.StringVar(&hostname, "hostname", hostname, "custom hostname for resque workers")
}

func flags() error {
Expand Down
10 changes: 7 additions & 3 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ type process struct {
}

func newProcess(id string, queues []string) (*process, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
if hostname == "" {
h, err := os.Hostname()
if err != nil {
return nil, err
}

hostname = h
}

return &process{
Expand Down