This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
minifaas/engine/queue.go

36 lines
701 B
Go

package engine
import (
"crypto/sha256"
"fmt"
"strings"
)
func GenContainerPrefix(jobtype string) string {
return fmt.Sprintf("minifaas-%x-", sha256.Sum224([]byte(jobtype)))
}
func FilterRunningContainers(jobtype string, ctrs map[string]string) (ret []string) {
prefix := GenContainerPrefix(jobtype)
for cname, _ := range ctrs {
if jobtype == "" || strings.HasPrefix(cname, prefix) {
ret = append(ret, cname)
}
}
return
}
func CountRunningContainers(jobtype string, ctrs map[string]string) (n int) {
prefix := GenContainerPrefix(jobtype)
for cname, _ := range ctrs {
if jobtype == "" || strings.HasPrefix(strings.TrimPrefix(cname, "/"), prefix) {
n += 1
}
}
return
}