@@ 7,6 7,7 @@ import (
work "git.sr.ht/~sircmpwn/dowork"
"github.com/labstack/echo/v4"
+ "hg.code.netlandish.com/~netlandish/gobwebs"
"petersanchez.com/carrier"
)
@@ 49,13 50,17 @@ func (s *ServiceQueue) mailTask(msg *carrier.Message) *work.Task {
s.logger.Printf("Error sending mail: %v", err)
}
return err
- }).Retries(5).After(func(ctx context.Context, task *work.Task) {
+ }).Retries(5).Before(func(ctx context.Context, task *work.Task) {
+ gobwebs.TaskIDWork(task)
+ s.logger.Printf(
+ "Running email task %s for the %d attempt.", task.Metadata["id"], task.Attempts())
+ }).After(func(ctx context.Context, task *work.Task) {
if task.Result() == nil {
- s.logger.Printf("Mail to %s sent after %d attempts",
- strings.Join(msg.GetAllRcpts(), ", "), task.Attempts())
+ s.logger.Printf("Mail %s to %s sent after %d attempts",
+ task.Metadata["id"], strings.Join(msg.GetAllRcpts(), ", "), task.Attempts())
} else {
- s.logger.Printf("Mail to %s failed after %d attempts: %v",
- strings.Join(msg.GetAllRcpts(), ", "), task.Attempts(), task.Result())
+ s.logger.Printf("Mail %s to %s failed after %d attempts: %v",
+ task.Metadata["id"], strings.Join(msg.GetAllRcpts(), ", "), task.Attempts(), task.Result())
}
})
}
@@ 0,0 1,14 @@
+package gobwebs
+
+import (
+ work "git.sr.ht/~sircmpwn/dowork"
+ "github.com/segmentio/ksuid"
+)
+
+// TaskIDWork sets a task ID via the Before option for a dowork
+// task
+func TaskIDWork(task *work.Task) {
+ if _, ok := task.Metadata["id"]; !ok {
+ task.Metadata["id"] = ksuid.New().String()
+ }
+}