Add queuing system
This commit is contained in:
parent
bb86563ed9
commit
f2eacf41cf
6 changed files with 106 additions and 17 deletions
|
|
@ -16,17 +16,17 @@ func newCli() (*client.Client, error) {
|
|||
return client.NewClientWithOpts(client.FromEnv)
|
||||
}
|
||||
|
||||
func Ps() ([]types.Container, error) {
|
||||
func Ps(opts types.ContainerListOptions) ([]types.Container, error) {
|
||||
cli, err := newCli()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cli.ContainerList(context.Background(), types.ContainerListOptions{})
|
||||
return cli.ContainerList(context.Background(), opts)
|
||||
}
|
||||
|
||||
func PsName() (ret map[string]string, err error) {
|
||||
containers, err := Ps()
|
||||
containers, err := Ps(types.ContainerListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -41,6 +41,24 @@ func PsName() (ret map[string]string, err error) {
|
|||
return ret, err
|
||||
}
|
||||
|
||||
func GetContainer(containerID string) (ctr types.ContainerJSON, err error) {
|
||||
cli, err := newCli()
|
||||
if err != nil {
|
||||
return types.ContainerJSON{}, err
|
||||
}
|
||||
|
||||
return cli.ContainerInspect(context.Background(), containerID)
|
||||
}
|
||||
|
||||
func HasStarted(containerID string) bool {
|
||||
ctr, err := GetContainer(containerID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return ctr.State.Status == "running" || ctr.State.Status == "paused" || ctr.State.Status == "restarting" || ctr.State.Status == "removing" || ctr.State.Status == "exited" || ctr.State.Status == "dead"
|
||||
}
|
||||
|
||||
func Create(jobtype string, image string, cmd []string, mounts []mount.Mount) (string, error) {
|
||||
cli, err := newCli()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,23 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const CTR_NAME_PREFIX = "minifaas"
|
||||
|
||||
func GenContainerPrefix(jobtype string) string {
|
||||
return fmt.Sprintf("minifaas-%x-", sha256.Sum224([]byte(jobtype)))
|
||||
return fmt.Sprintf("%s-%x-", CTR_NAME_PREFIX, sha256.Sum224([]byte(jobtype)))
|
||||
}
|
||||
|
||||
func ParseContainerName(name string) (jobtype, id string, err error) {
|
||||
if !strings.HasPrefix(name, "/"+CTR_NAME_PREFIX+"-") {
|
||||
return "", "", fmt.Errorf("This is not a %s job: starting with %q", CTR_NAME_PREFIX, name)
|
||||
}
|
||||
|
||||
tmp := strings.Split(name, "-")
|
||||
if len(tmp) < 3 {
|
||||
return "", "", fmt.Errorf("This is not a %s job: %q didn't has at least 3 args", CTR_NAME_PREFIX, name)
|
||||
}
|
||||
|
||||
return tmp[1], strings.Join(tmp[2:], "-"), nil
|
||||
}
|
||||
|
||||
func FilterRunningContainers(jobtype string, ctrs map[string]string) (ret []string) {
|
||||
|
|
|
|||
Reference in a new issue