Beispiel #1
0
func (c *config) logger() *log.Logger {
	if c.l != nil {
		return c.l
	}
	if len(c.logfile) > 0 {
		if c.logfile == "-" {
			c.l = log.New(os.Stdout, "", log.LstdFlags)
		} else {
			w := hupwriter.New(c.logfile, c.pidfile)
			c.l = log.New(w, "", log.LstdFlags)
		}
	}
	if c.l == nil {
		c.l = log.New(ioutil.Discard, "", 0)
	}
	return c.l
}
Beispiel #2
0
func (c *config) toApp() (*app, error) {
	// Retrieve an AWS auth.
	auth, err := awsutil.GetAuth("sqs-notify")
	if err != nil {
		return nil, err
	}

	// Determine a region.
	region, ok := aws.Regions[c.region]
	if !ok {
		return nil, errors.New("unknown region:" + c.region)
	}

	// logfile and pidfile.
	var l *log.Logger
	if len(c.logfile) > 0 {
		if c.logfile == "-" {
			l = log.New(os.Stdout, "", log.LstdFlags)
		} else {
			w := hupwriter.New(c.logfile, c.pidfile)
			l = log.New(w, "", log.LstdFlags)
		}
	}

	notify := sqsnotify.New(auth, region, c.queue)

	jobs, err := c.newJobs()
	if err != nil {
		return nil, err
	}

	return &app{
		logger:   l,
		auth:     auth,
		region:   region,
		worker:   c.worker,
		nowait:   c.nowait,
		retryMax: c.retryMax,
		jobs:     jobs,
		notify:   notify,
		cmd:      c.cmd,
		args:     c.args,
	}, nil
}