Touch messages so they don't time out while processing

This commit is contained in:
2024-10-18 17:52:30 +02:00
parent ed8eaf67a2
commit 584084c1bc

View File

@@ -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)