Implement basic queue, where is it impossible to run two identical job
in parallel
This commit is contained in:
parent
8259aaa474
commit
af96f82831
4 changed files with 81 additions and 4 deletions
|
|
@ -3,8 +3,33 @@ 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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue