Exemple #1
0
// taskFromInstance converts a scheduler.Instance into a Task.
// It pulls some of its data from empire specific environment variables if they have been set.
// Once ECS supports this data natively, we can stop doing this.
func taskFromInstance(i *scheduler.Instance) *Task {
	version := i.Process.Env["EMPIRE_RELEASE"]
	if version == "" {
		version = "v0"
	}

	return &Task{
		Name:    fmt.Sprintf("%s.%s.%s", version, i.Process.Type, i.ID),
		Type:    string(i.Process.Type),
		Command: Command(i.Process.Command),
		Constraints: Constraints{
			CPUShare: constraints.CPUShare(i.Process.CPUShares),
			Memory:   constraints.Memory(i.Process.MemoryLimit),
			Nproc:    constraints.Nproc(i.Process.Nproc),
		},
		State:     i.State,
		UpdatedAt: i.UpdatedAt,
	}
}
Exemple #2
0
				var command Command
				var quantity, memory, cpu, nproc int
				if err := rows.Scan(&release, &id, &ptype, &quantity, &command, &memory, &cpu, &nproc); err != nil {
					return err
				}
				if formations[release] == nil {
					formations[release] = make(Formation)
				}

				f := formations[release]
				f[ptype] = Process{
					Command:  command,
					Quantity: quantity,
					Memory:   constraints.Memory(memory),
					CPUShare: constraints.CPUShare(cpu),
					Nproc:    constraints.Nproc(nproc),
				}
			}

			if err := rows.Err(); err != nil {
				return err
			}

			rows.Close()

			for id, f := range formations {
				_, err = tx.Exec(`UPDATE releases SET formation = $1 WHERE id = $2`, f, id)
				if err != nil {
					return err
				}
			}
Exemple #3
0
package empire

import (
	"encoding/json"
	"fmt"

	. "github.com/remind101/empire/pkg/bytesize"
	"github.com/remind101/empire/pkg/constraints"
)

var (
	Constraints1X = Constraints{constraints.CPUShare(256), constraints.Memory(512 * MB), constraints.Nproc(256)}
	Constraints2X = Constraints{constraints.CPUShare(512), constraints.Memory(1 * GB), constraints.Nproc(512)}
	ConstraintsPX = Constraints{constraints.CPUShare(1024), constraints.Memory(6 * GB), 0}

	// NamedConstraints maps a heroku dynos size to a Constraints.
	NamedConstraints = map[string]Constraints{
		"1X": Constraints1X,
		"2X": Constraints2X,
		"PX": ConstraintsPX,
	}

	// DefaultConstraints defaults to 1X process size.
	DefaultConstraints = Constraints1X
)

// Constraints aliases the constraints.Constraints type to implement the
// json.Unmarshaller interface.
type Constraints constraints.Constraints

func parseConstraints(con string) (*Constraints, error) {