Add queuing system

This commit is contained in:
nemunaire 2021-07-31 17:16:38 +02:00
commit f2eacf41cf
6 changed files with 106 additions and 17 deletions

View file

@ -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 {