Initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
type Run struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func runJob(job config.Job) {
|
||||
if job.Folder != nil {
|
||||
log.Debugf("Job configured with folder \"%v\"", *job.Folder)
|
||||
} else if job.URL != nil {
|
||||
log.Debugf("Job configured with URL \"%v\"", *job.URL)
|
||||
}
|
||||
}
|
||||
|
||||
func runnerListen(ch chan Run, jobs map[string]config.Job) {
|
||||
for {
|
||||
run := <-ch
|
||||
log.Debugf("Got Run: %v", run)
|
||||
job, exists := jobs[run.Name]
|
||||
if exists {
|
||||
log.Infof("Launching run for job %v", run.Name)
|
||||
go runJob(job)
|
||||
} else {
|
||||
log.Errorf("No configured job with name %v", run.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StartRunner(jobs map[string]config.Job) (chan Run, error) {
|
||||
ch := make(chan Run)
|
||||
|
||||
go runnerListen(ch, jobs)
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
Reference in New Issue
Block a user