From 752ee7db471f3d5368f30a5841d5286465a8d5ab Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sat, 19 Aug 2023 19:32:22 +0200 Subject: ref: Better worker description This is hard coded as I always want to check that. --- pkg/worker/worker.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index b768320..4547166 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -25,6 +25,10 @@ type ( } ) +const ( + format = "2006.01.02 15:04:05" +) + func NewTaskPool() *TaskPool { return &TaskPool{} } @@ -38,12 +42,15 @@ func (w *Work) run(ctx context.Context) error { case <-ctx.Done(): return ctx.Err() case <-timer.C: - fmt.Println("Process starting: ", w.Name) + now := time.Now() + fmt.Printf("[%s] Process starting: %s\n", time.Now().Format(format), w.Name) if err := w.Task.Start(ctx); err != nil && !errors.Is(err, context.Canceled) { - fmt.Println("Process errored: ", w.Name, err.Error()) + since := time.Since(now) + fmt.Printf("[%s] Process errored (%s): %s\n", time.Now().Format(format), since.String(), w.Name) return err } else { - fmt.Println("Process done: ", w.Name) + since := time.Since(now) + fmt.Printf("[%s] Process done (%s): %s\n", time.Now().Format(format), since.String(), w.Name) } } timer.Reset(w.wait) -- cgit v1.2.3