Touch messages so they don't time out while processing
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user