// 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: i.Process.Command, Constraints: Constraints{ CPUShare: constraints.CPUShare(i.Process.CPUShares), Memory: constraints.Memory(i.Process.MemoryLimit), }, State: i.State, UpdatedAt: i.UpdatedAt, } }
// processStateFromInstance converts a service.Instance into a ProcessState. // 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 processStateFromInstance(i *service.Instance) *ProcessState { createdAt := i.UpdatedAt if t, err := time.Parse(time.RFC3339, i.Process.Env["EMPIRE_CREATED_AT"]); err == nil { createdAt = t } version := i.Process.Env["EMPIRE_RELEASE"] if version == "" { version = "v0" } return &ProcessState{ Name: fmt.Sprintf("%s.%s.%s", version, i.Process.Type, i.ID), Command: i.Process.Command, Constraints: Constraints{ CPUShare: constraints.CPUShare(i.Process.CPUShares), Memory: constraints.Memory(i.Process.MemoryLimit), }, State: i.State, UpdatedAt: createdAt, // This is the best data we have, until ECS gives us UpdatedAt } }
var release, id, ptype string 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 }
"database/sql" "database/sql/driver" "encoding/json" "fmt" "time" "github.com/jinzhu/gorm" "github.com/lib/pq/hstore" . "github.com/remind101/empire/pkg/bytesize" "github.com/remind101/empire/pkg/constraints" "github.com/remind101/empire/pkg/service" "golang.org/x/net/context" ) var ( Constraints1X = Constraints{constraints.CPUShare(256), constraints.Memory(512 * MB)} Constraints2X = Constraints{constraints.CPUShare(512), constraints.Memory(1 * GB)} ConstraintsPX = Constraints{constraints.CPUShare(1024), constraints.Memory(6 * GB)} // 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 ) // ProcessQuantityMap represents a map of process types to quantities.