From 7fc435481d1964cf8243ef12ff1cae9a2e61b29c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 29 Jun 2023 15:56:35 +0200 Subject: [PATCH] wip --- lib/model/util.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/model/util.go b/lib/model/util.go index 3bc9079b6..d2fe8e735 100644 --- a/lib/model/util.go +++ b/lib/model/util.go @@ -157,8 +157,13 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i // by a large amount at the end of the operation. func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) { t0 := time.Now() + defer func() { + counter.Add(time.Since(t0).Seconds()) + }() + ticker := time.NewTicker(time.Second) defer ticker.Stop() + for { select { case <-ticker.C: @@ -166,7 +171,7 @@ func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) { counter.Add(t1.Sub(t0).Seconds()) t0 = t1 case <-ctx.Done(): - counter.Add(time.Since(t0).Seconds()) + return } } }