Skip to content

Commit

Permalink
add Update time to flowlord (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbsmith7741 authored Dec 21, 2020
1 parent 13f27a4 commit b40f6aa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions apps/taskmasters/flowlord/taskmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

gtools "github.com/jbsmith7741/go-tools"
"github.com/pcelvng/task"
"github.com/pcelvng/task/bus"
"github.com/pkg/errors"
Expand All @@ -25,6 +26,7 @@ import (

type taskMaster struct {
initTime time.Time
nextUpdate time.Time
path string
dur time.Duration
producer bus.Producer
Expand All @@ -38,9 +40,10 @@ type taskMaster struct {
}

type stats struct {
RunTime string `json:"runtime"`
Workflow map[string]int `json:"workflow"`
Entries map[string]cEntry `json:"job"`
RunTime string `json:"runtime"`
NextUpdate string `json:"next_cache_update"`
Workflow map[string]int `json:"workflow"`
Entries map[string]cEntry `json:"job"`
}

type cEntry struct {
Expand Down Expand Up @@ -76,9 +79,10 @@ func New(app *bootstrap.TaskMaster) bootstrap.Runner {

func (tm *taskMaster) Info() interface{} {
sts := stats{
RunTime: time.Now().Sub(tm.initTime).String(),
Entries: make(map[string]cEntry),
Workflow: make(map[string]int),
RunTime: gtools.PrintDuration(time.Now().Sub(tm.initTime)),
NextUpdate: tm.nextUpdate.Format("2006-01-02T15:04:05"),
Entries: make(map[string]cEntry),
Workflow: make(map[string]int),
}

for _, e := range tm.cron.Entries() {
Expand All @@ -105,6 +109,7 @@ func (tm *taskMaster) Info() interface{} {
// if any changes have been made to the workflow files
func (tm *taskMaster) AutoUpdate() {
for {

files, err := tm.Cache.Refresh()
if err != nil {
log.Println("error reloading workflow files", err)
Expand All @@ -122,6 +127,7 @@ func (tm *taskMaster) AutoUpdate() {
tcron.Stop()
}
}
tm.nextUpdate = time.Now().Add(tm.dur)
<-time.Tick(tm.dur)
}
}
Expand Down

0 comments on commit b40f6aa

Please sign in to comment.