app/task/profile.go

77 lines
1.2 KiB
Go
Raw Normal View History

2021-12-16 04:11:33 +00:00
package task
import (
2021-12-18 13:32:46 +00:00
"sync"
2021-12-16 04:11:33 +00:00
"time"
cron "github.com/robfig/cron/v3"
)
var Reporter chan *Report
2021-12-18 13:32:46 +00:00
var started chan struct{}
var wg sync.WaitGroup
var quit chan struct{}
func init() {
Reporter = make(chan *Report)
started = make(chan struct{}, 1)
quit = make(chan struct{}, 1)
}
type Receiver func(*Report)
var ReportReceiver Receiver = func(r *Report) {}
2021-12-16 04:11:33 +00:00
type Report struct {
// Entry
2021-12-19 06:02:39 +00:00
Next time.Time
Prev time.Time
Entry cron.EntryID
2021-12-16 04:11:33 +00:00
// Task
2021-12-19 06:02:39 +00:00
ID string
Description string
Group string
2021-12-16 04:11:33 +00:00
// _task
2021-12-19 06:02:39 +00:00
Name string
Spec string
Once bool
Args []interface{}
Carry interface{}
2021-12-16 04:11:33 +00:00
// Report
2021-12-19 06:02:39 +00:00
Error error
2021-12-16 04:11:33 +00:00
}
type Profile struct {
2021-12-19 06:02:39 +00:00
Scheduled []*Report
2021-12-16 04:11:33 +00:00
}
func GetProfile() *Profile {
2021-12-17 09:27:56 +00:00
p := &Profile{}
2021-12-16 04:11:33 +00:00
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,
ID: t.Task.ID,
Description: t.Task.Description,
Group: t.Task.Group,
2021-12-19 06:02:39 +00:00
Name: t.name,
2021-12-16 04:11:33 +00:00
Spec: t.spec,
Once: t.once,
Args: t.args,
Carry: t.carry,
}
p.Scheduled = append(p.Scheduled, r)
}
return p
}