Changelog-added: Be sure we are shutting down background tasks correctly
to avoid any data errors, etc.
Signed-off-by: Peter Sanchez <peter@netlandish.com>
---
cmd/links/main.go | 6 +++++-
cmd/links/parse.go | 3 ++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/cmd/links/main.go b/cmd/links/main.go
index 4372a40..732886e 100644
--- a/cmd/links/main.go
+++ b/cmd/links/main.go
@@ -8,6 +8,7 @@ import (
"os"
"slices"
"strings"
+ "sync"
"text/template"
"time"
@@ -385,8 +386,11 @@ func run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
- go parseBaseURLs(ctx, srv)
+ wg := new(sync.WaitGroup)
+ wg.Add(1)
+ go parseBaseURLs(ctx, srv, wg.Done)
srv.Run()
+ wg.Wait()
return nil
}
diff --git a/cmd/links/parse.go b/cmd/links/parse.go
index 0cbe8a4..600d8eb 100644
--- a/cmd/links/parse.go
+++ b/cmd/links/parse.go
@@ -60,7 +60,8 @@ func runParse(ctx context.Context, srv *server.Server) error {
// This is a helper function to process base URL's that had errors
// when fetching them.
-func parseBaseURLs(ctx context.Context, srv *server.Server) {
+func parseBaseURLs(ctx context.Context, srv *server.Server, done func()) {
+ defer done()
nctx, cancel := context.WithCancel(context.Background())
nctx = server.ServerContext(nctx, srv)
nctx = database.Context(nctx, srv.DB)
--
2.47.2