firestormy/server/job.go

35 lines
866 B
Go
Executable File

package server
import (
"time"
"gitea.inhome.blapointe.com/local/firestormy/config"
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
"gitea.inhome.blapointe.com/local/firestormy/scheduler"
)
func toMap(j *scheduler.Job, output bool) map[string]interface{} {
tz, err := time.LoadLocation("America/Denver")
if err != nil {
panic(err)
}
out := make(map[string]interface{})
out["disabled"] = j.Disabled
out["id"] = j.Name
out["title"] = j.Title
out["cron"] = j.Schedule
out["language"] = j.Runner.String()
b, _ := config.Store.Get(j.Name, ns.JobsRaw...)
out["script"] = string(b)
out["last"] = map[string]interface{}{
"run": j.LastRun.In(tz).Format(`2006-01-02 15:04:05 MST`),
"runtime": j.LastRuntime.String(),
"status": j.LastStatus,
}
if output {
out["output"] = j.LastOutput
out["status"] = j.LastStatus
}
return out
}