mirror of
https://github.com/nxshock/gron.git
synced 2024-11-27 03:41:00 +05:00
Add job categories
This commit is contained in:
parent
96587792cc
commit
6dd6112040
@ -8,6 +8,7 @@
|
||||
2. Create job config in `gron.d/job1.conf` ([TOML](https://en.wikipedia.org/wiki/TOML) format):
|
||||
```toml
|
||||
Type = "cmd" # command execution
|
||||
Category = "Test jobs" # jobs category name
|
||||
Cron = "* * * * *" # cron instructions
|
||||
|
||||
Command = "echo Hello" # command to execute
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -40,13 +41,34 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
globalMutex.RLock()
|
||||
buf := new(bytes.Buffer)
|
||||
jobEntries := c.Entries()
|
||||
var jobs []*Job
|
||||
|
||||
jobs := make(map[string][]*Job)
|
||||
for _, jobEntry := range jobEntries {
|
||||
job := jobEntry.Job.(*Job)
|
||||
job.NextLaunch = jobEntry.Next.Format(config.TimeFormat)
|
||||
jobs = append(jobs, job)
|
||||
jobs[job.JobConfig.Category] = append(jobs[job.JobConfig.Category], job)
|
||||
}
|
||||
_ = templates.ExecuteTemplate(buf, "index.htm", jobs)
|
||||
|
||||
var keys []string
|
||||
for k, v := range jobs {
|
||||
keys = append(keys, k)
|
||||
|
||||
sort.Slice(v, func(i, j int) bool {
|
||||
return v[i].Name < v[j].Name
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
return keys[i] < keys[j]
|
||||
})
|
||||
|
||||
_ = templates.ExecuteTemplate(buf, "index.htm", struct {
|
||||
Categories []string
|
||||
Jobs map[string][]*Job
|
||||
}{
|
||||
Categories: keys,
|
||||
Jobs: jobs,
|
||||
})
|
||||
globalMutex.RUnlock()
|
||||
|
||||
_, _ = buf.WriteTo(w)
|
||||
|
2
job.go
2
job.go
@ -21,6 +21,8 @@ import (
|
||||
type JobConfig struct {
|
||||
Type JobType
|
||||
|
||||
Category string
|
||||
|
||||
// JobType = Cmd
|
||||
Command string // command for execution
|
||||
|
||||
|
@ -20,7 +20,8 @@
|
||||
<a href="/shutdown">⏻ Shutdown</a>
|
||||
</div>
|
||||
</div>
|
||||
<h1>Job list</h1>
|
||||
{{range .Categories}}
|
||||
<h2>{{if eq . ""}}Other jobs{{else}}{{.}}{{end}}</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@ -33,7 +34,7 @@
|
||||
<th>Next launch</th>
|
||||
<th>Details</th>
|
||||
</tr>
|
||||
{{range .}}
|
||||
{{range (index $.Jobs .)}}
|
||||
<tr>
|
||||
<td class="no-padding">
|
||||
<form action="/start" method="get" id="form-{{.Name}}"></form>
|
||||
@ -50,7 +51,7 @@
|
||||
<td>{{.NextLaunch}}</td>
|
||||
<td class="centered"><a href="/details?jobName={{.Name}}">open</a></td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
</table>{{end}}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user