1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00

Add next launch time field

This commit is contained in:
nxshock 2022-03-28 19:55:43 +05:00
parent 330c94f8e1
commit c952ded006
3 changed files with 24 additions and 19 deletions

View File

@ -33,8 +33,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
buf := new(bytes.Buffer)
jobEntries := c.Entries()
var jobs []*Job
for _, v := range jobEntries {
jobs = append(jobs, v.Job.(*Job))
for _, jobEntry := range jobEntries {
job := jobEntry.Job.(*Job)
job.NextLaunch = jobEntry.Next.Format(config.TimeFormat)
jobs = append(jobs, job)
}
indexTemplate.ExecuteTemplate(buf, "index", jobs)
globalMutex.RUnlock()

View File

@ -193,6 +193,7 @@
<th>Start time</th>
<th>Finish time</th>
<th>Duration</th>
<th>Next launch</th>
<th>Last error</th>
</tr>
{{range .}}<tr>
@ -208,6 +209,7 @@
<td>{{.LastStartTime}}</td>
<td>{{.LastEndTime}}</td>
<td align="right">{{.LastExecutionDuration}}</td>
<td>{{.NextLaunch}}</td>
<td class="smaller red">{{.LastError}}</td>
</tr>{{end}}
</table>

35
job.go
View File

@ -20,6 +20,24 @@ type JobConfig struct {
Description string
}
type Job struct {
Name string // from filename
Cron string // cron decription
Command string // command for execution
Params []string // command params
FileName string // short job name
Description string // job description
// Fields for stats
CurrentRunningCount int
LastStartTime string
LastEndTime string
LastExecutionDuration string
LastError string
NextLaunch string
}
var globalMutex sync.RWMutex
func readJob(filePath string) (*Job, error) {
@ -49,23 +67,6 @@ func (js *JobConfig) Write() {
ioutil.WriteFile("job.conf", buf.Bytes(), 0644)
}
type Job struct {
Name string // from filename
Cron string // cron decription
Command string // command for execution
Params []string // command params
FileName string // short job name
Description string // job description
// Fields for stats
CurrentRunningCount int
LastStartTime string
LastEndTime string
LastExecutionDuration string
LastError string
}
func (j *Job) Run() {
startTime := time.Now()