Skip to content
Snippets Groups Projects
Commit d3ce155d authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Add retry mechanism on saving tasks to history collection

parent a6ed68a5
No related branches found
No related tags found
1 merge request!4Task execution of independent tasks
Showing
with 11 additions and 3 deletions
......@@ -4,6 +4,7 @@ go 1.17
require (
code.vereign.com/gaiax/tsa/golib v0.0.0-20220321093827-5fdf8f34aad9
github.com/cenkalti/backoff/v4 v4.1.3
github.com/google/uuid v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
go.mongodb.org/mongo-driver v1.8.4
......
......@@ -56,7 +56,6 @@ func (w *Worker) Start(ctx context.Context) {
}
if err := w.storage.SaveTaskHistory(ctx, executed); err != nil {
// TODO: is this fatal error, should the task be re-executed?
logger.Error("error saving task history", zap.Error(err))
continue
}
......
......@@ -4,6 +4,7 @@ import (
"context"
"strings"
"github.com/cenkalti/backoff/v4"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
......@@ -109,6 +110,11 @@ func (s *Storage) Unack(ctx context.Context, t *task.Task) error {
// SaveTaskHistory saves a task to the `tasksHistory` collection.
func (s *Storage) SaveTaskHistory(ctx context.Context, task *task.Task) error {
_, err := s.tasksHistory.InsertOne(ctx, task)
return err
insert := func() error {
_, err := s.tasksHistory.InsertOne(ctx, task)
return err
}
b := backoff.WithContext(backoff.NewExponentialBackOff(), ctx)
return backoff.Retry(insert, b)
}
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment