From 584084c1bc387642bc34ed3c6fb73fbe1f0d9d88 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 18 Oct 2024 17:52:30 +0200 Subject: [PATCH] Touch messages so they don't time out while processing --- downloader/main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/downloader/main.go b/downloader/main.go index 8299802..a8319b0 100644 --- a/downloader/main.go +++ b/downloader/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "io" @@ -46,7 +47,24 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error { Error.Printf("Error unmarshalling message: %v", err) return err } - log.Printf("Downloading %s", data.Link) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + go func() { + ticker := time.NewTicker(5 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + message.Touch() + case <-ctx.Done(): + return + } + } + }() + err = Download(data.Link) if err != nil { Error.Printf("Error downloading %s: %v", data.Link, err)