Touch messages so they don't time out while processing
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -46,7 +47,24 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
|||||||
Error.Printf("Error unmarshalling message: %v", err)
|
Error.Printf("Error unmarshalling message: %v", err)
|
||||||
return 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)
|
err = Download(data.Link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error downloading %s: %v", data.Link, err)
|
Error.Printf("Error downloading %s: %v", data.Link, err)
|
||||||
|
Reference in New Issue
Block a user