Reload job in ui

This commit is contained in:
bel
2020-03-15 23:04:48 +00:00
parent 19d4b645b8
commit 8138e31e53
12 changed files with 275 additions and 93 deletions

View File

@@ -15,6 +15,8 @@ import (
cron "github.com/robfig/cron/v3"
)
var Schedule *Scheduler = New()
type Scheduler struct {
cron *cron.Cron
running map[string]cron.EntryID
@@ -154,6 +156,40 @@ func (s *Scheduler) loadJobFromStore(k string) (*Job, error) {
return j, err
}
func (s *Scheduler) Update(j *Job) error {
entryID, ok := s.getEntry(j)
if !ok {
return errors.New("job not found in storage")
}
i, err := s.loadJobFromStore(j.Name)
if err != nil {
return err
}
j.LastStatus = i.LastStatus
j.LastOutput = i.LastOutput
j.LastRuntime = i.LastRuntime
j.LastRun = i.LastRun
b, err := j.Encode()
if err != nil {
return err
}
if err := config.Store.Set(j.Name, b, ns.Jobs...); err != nil {
return err
}
s.cron.Remove(entryID)
entryID, err = s.cron.AddJob(j.Schedule, j)
if err != nil {
return err
}
s.running[j.Name] = entryID
return nil
}
func (s *Scheduler) Add(j *Job) error {
if _, ok := s.getEntry(j); ok {
return ErrDuplicateJob