From 835cf6b12fd3d4417b3900822cf63b91f54ff1ac Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 27 Dec 2017 12:56:46 +0100 Subject: [PATCH] cmd control status: warn about inactive tasks refs #10 --- cmd/control.go | 9 ++++++++- cmd/logging_formatters.go | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/control.go b/cmd/control.go index cece051..6128c8b 100644 --- a/cmd/control.go +++ b/cmd/control.go @@ -236,8 +236,9 @@ func doControlStatusCmd(cmd *cobra.Command, args []string) { fmt.Fprint(&header, "") } fmt.Fprint(&header, " ") + const TASK_STALLED_HOLDOFF_DURATION = 10 * time.Second + sinceLastUpdate := now.Sub(task.LastUpdate) if !task.Idle || task.ProgressRx != 0 || task.ProgressTx != 0 { - fmt.Fprintf(&header, "(%s / %s , Rx/Tx", humanize.Bytes(uint64(task.ProgressRx)), humanize.Bytes(uint64(task.ProgressTx))) @@ -247,6 +248,12 @@ func doControlStatusCmd(cmd *cobra.Command, args []string) { fmt.Fprint(&header, ")") } fmt.Fprint(&header, "\n") + if !task.Idle && !task.LastUpdate.IsZero() && sinceLastUpdate >= TASK_STALLED_HOLDOFF_DURATION { + fmt.Fprintf(&header, " WARNING: last update %s ago at %s)", + sinceLastUpdate.String(), + task.LastUpdate.Format(HumanFormatterDateFormat)) + fmt.Fprint(&header, "\n") + } io.Copy(os.Stdout, &header) var logBuf bytes.Buffer diff --git a/cmd/logging_formatters.go b/cmd/logging_formatters.go index 754d26a..cf0f985 100644 --- a/cmd/logging_formatters.go +++ b/cmd/logging_formatters.go @@ -44,6 +44,8 @@ type HumanFormatter struct { ignoreFields map[string]bool } +const HumanFormatterDateFormat = time.RFC3339 + func (f *HumanFormatter) SetMetadataFlags(flags MetadataFlags) { f.metadataFlags = flags } @@ -69,7 +71,7 @@ func (f *HumanFormatter) Format(e *logger.Entry) (out []byte, err error) { var line bytes.Buffer if f.metadataFlags&MetadataTime != 0 { - fmt.Fprintf(&line, "%s ", e.Time.Format(time.RFC3339)) + fmt.Fprintf(&line, "%s ", e.Time.Format(HumanFormatterDateFormat)) } if f.metadataFlags&MetadataLevel != 0 { fmt.Fprintf(&line, "[%s]", e.Level.Short())