Example #1
0
func (cf *Config) Apply() (err error) {
	// runtime
	if cf.MaxProcs <= 0 {
		cf.MaxProcs = runtime.NumCPU()
	}
	runtime.GOMAXPROCS(cf.MaxProcs)

	// logging
	if err := lg.SetLevelString(strings.ToLower(cf.LogLevel)); err != nil {
		return err
	}

	// limits
	if cf.Limits.RequestTimeoutStr != "" {
		to, err := time.ParseDuration(cf.Limits.RequestTimeoutStr)
		if err != nil {
			return err
		}
		cf.Limits.RequestTimeout = to
	}
	if cf.Limits.BacklogTimeoutStr != "" {
		to, err := time.ParseDuration(cf.Limits.BacklogTimeoutStr)
		if err != nil {
			return err
		}
		cf.Limits.BacklogTimeout = to
	}

	return nil
}
Example #2
0
File: qmd.go Project: pressly/qmd
func New(conf *config.Config) (*Qmd, error) {
	db, err := NewDB(conf.DB.RedisURI)
	if err != nil {
		return nil, err
	}

	if err := db.Ping(); err != nil {
		return nil, err
	}

	queue, err := disque.New(conf.Queue.DisqueURI)
	if err != nil {
		return nil, err
	}
	queue.Use(disque.Config{
		RetryAfter: time.Duration(conf.MaxExecTime) * time.Second,
		Timeout:    time.Second,
	})

	if err := queue.Ping(); err != nil {
		return nil, err
	}

	// TODO: SlackNOP.
	slack := &SlackNotifier{
		WebhookURL: conf.Slack.WebhookURL,
		Channel:    conf.Slack.Channel,
		Prefix:     fmt.Sprintf("%v: ", conf.URL),
	}

	qmd := &Qmd{
		Config:             conf,
		DB:                 db,
		Queue:              queue,
		Workers:            make(chan Worker, conf.MaxJobs),
		ClosingListenQueue: make(chan struct{}),
		ClosingWorkers:     make(chan struct{}),
		Slack:              slack,
	}

	if err := lg.SetLevelString("debug"); err != nil {
		return nil, err
	}

	lg.AlertFn = func(level lg.Level, msg string) {
		switch level {
		case lg.ErrorLevel, lg.FatalLevel, lg.PanicLevel:
			qmd.Slack.Notify(msg)
		}
	}

	return qmd, nil
}
Example #3
0
func (cf *Config) SetupLogging() {
	err := lg.SetLevelString(strings.ToLower(cf.Server.LogLevel))
	if err != nil {
		log.Fatal(err)
	}
}