Пример #1
0
// SetEnvsToApp adds environment variables to an app, serializing the resulting
// list of environment variables in all units of apps. This method can
// serialize them directly or using a queue.
//
// Besides the slice of environment variables, this method also takes two other
// parameters: publicOnly indicates whether only public variables can be
// overridden (if set to false, setEnvsToApp may override a private variable).
//
// If useQueue is true, it will use a queue to write the environment variables
// in the units of the app.
func (app *App) SetEnvsToApp(envs []bind.EnvVar, publicOnly, useQueue bool) error {
	if len(envs) > 0 {
		for _, env := range envs {
			set := true
			if publicOnly {
				e, err := app.getEnv(env.Name)
				if err == nil && !e.Public {
					set = false
				}
			}
			if set {
				app.setEnv(env)
			}
		}
		if err := db.Session.Apps().Update(bson.M{"name": app.Name}, app); err != nil {
			return err
		}
		if useQueue {
			return queue.Put(&queue.Message{Action: RegenerateApprc, Args: []string{app.Name}})
		}
		app.SerializeEnvVars()
	}
	return nil
}
Пример #2
0
func (a *App) enqueue(msgs ...queue.Message) {
	for _, msg := range msgs {
		copy := msg
		queue.Put(&copy)
	}
}