Create a list of known jobs

This commit is contained in:
nemunaire 2021-05-09 18:02:23 +02:00
commit 1fd0a2d8f3
5 changed files with 46 additions and 17 deletions

39
jobs.go Normal file
View file

@ -0,0 +1,39 @@
package main
import (
"github.com/docker/docker/api/types/mount"
"github.com/nemunaire/minifaas/engine/docker"
)
type Job struct {
Image string
Cmd []string
DataMount bool
}
var jobs = map[string]Job{
"counter": {
Image: "alpine",
Cmd: []string{"sh", "-c", "touch /data/work_done; for i in `seq 10`; do echo $i; sleep 0.5; done"},
DataMount: true,
},
}
func RunJob(jobtype string) (string, error) {
var mnts []mount.Mount
if jobs[jobtype].DataMount {
myVolume, err := docker.CreateVolumeDir("/data", false)
if err != nil {
return "", err
}
mnts = append(mnts, *myVolume)
}
return docker.Run(
jobtype,
jobs[jobtype].Image,
jobs[jobtype].Cmd,
mnts,
)
}