Create a list of known jobs
This commit is contained in:
parent
5aa2d72da0
commit
1fd0a2d8f3
5 changed files with 46 additions and 17 deletions
39
jobs.go
Normal file
39
jobs.go
Normal 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,
|
||||
)
|
||||
}
|
||||
Reference in a new issue