66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package task
|
|
|
|
import (
|
|
"time"
|
|
|
|
cron "github.com/robfig/cron/v3"
|
|
)
|
|
|
|
var Reporter chan *Report
|
|
|
|
type Report struct {
|
|
// Entry
|
|
Next time.Time `json:"next"`
|
|
Prev time.Time `json:"prev"`
|
|
Entry cron.EntryID `json:"entry_id"`
|
|
|
|
// Task
|
|
Name string `json:"name"`
|
|
ID string `json:"id"`
|
|
Description string `json:"description"`
|
|
Group string `json:"grp"`
|
|
|
|
// _task
|
|
Spec string `json:"spec"`
|
|
Once bool `json:"once"`
|
|
Args []interface{} `json:"args"`
|
|
Carry interface{} `json:"carry"`
|
|
|
|
// Report
|
|
Error error `json:"error,omitempty"`
|
|
}
|
|
|
|
type Profile struct {
|
|
Tasks map[string]*Task
|
|
Scheduled []*Report `json:"scheduled"`
|
|
}
|
|
|
|
func GetProfile() *Profile {
|
|
p := &Profile{
|
|
Tasks: GetTasks(),
|
|
}
|
|
entries := c.Entries()
|
|
for i := 0; i < len(entries); i++ {
|
|
t, ok := entries[i].Job.(*_task)
|
|
if !ok {
|
|
continue
|
|
}
|
|
r := &Report{
|
|
Next: entries[i].Next,
|
|
Prev: entries[i].Prev,
|
|
Entry: entries[i].ID,
|
|
Name: t.Task.Name,
|
|
ID: t.Task.ID,
|
|
Description: t.Task.Description,
|
|
Group: t.Task.Group,
|
|
Spec: t.spec,
|
|
Once: t.once,
|
|
Args: t.args,
|
|
Carry: t.carry,
|
|
}
|
|
p.Scheduled = append(p.Scheduled, r)
|
|
}
|
|
|
|
return p
|
|
}
|