Skip to content

Commit

Permalink
if allowing retry the unset the failed state
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-bate committed Aug 28, 2023
1 parent acd694a commit c739eb2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
8 changes: 4 additions & 4 deletions dexcom/fetch/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ func (r *Runner) Run(ctx context.Context, tsk *task.Task) bool {
}

if !skipToAvoidDexcomBackup {
ResetTask(tsk)
tsk.ClearError()

if serverSessionToken, sErr := r.AuthClient().ServerSessionToken(); sErr != nil {
r.logTaskError(tsk, errors.Wrap(sErr, "unable to get server session token"))
r.ignoreAndLogTaskError(tsk, errors.Wrap(sErr, "unable to get server session token"))
} else {
ctx = auth.NewContextWithServerSessionToken(ctx, serverSessionToken)
if taskRunner, tErr := NewTaskRunner(r, tsk); tErr != nil {
r.logTaskError(tsk, errors.Wrap(sErr, "unable to create task runner"))
r.ignoreAndLogTaskError(tsk, errors.Wrap(sErr, "unable to create task runner"))
} else if tErr = taskRunner.Run(ctx); tErr != nil {
ErrorOrRetryTask(tsk, errors.Wrap(tErr, "unable to run task runner"))
}
Expand All @@ -148,7 +148,7 @@ func (r *Runner) Run(ctx context.Context, tsk *task.Task) bool {
return true
}

func (r *Runner) logTaskError(tsk *task.Task, err error) {
func (r *Runner) ignoreAndLogTaskError(tsk *task.Task, err error) {
r.logger.Warnf("dexcom task %s error, task will be retried: %s", tsk.ID, err)
}

Expand Down
6 changes: 1 addition & 5 deletions dexcom/fetch/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func ErrorOrRetryTask(t *task.Task, err error) {
return
}
incrementTaskRetryCount(t)
t.State = task.TaskStateCompleted
}
}

Expand All @@ -50,11 +51,6 @@ func FailTask(l log.Logger, t *task.Task, err error) error {
return err
}

func ResetTask(t *task.Task) {
t.ClearError()
t.Data[dexcomTaskRetryField] = 0
}

func shouldTaskError(t *task.Task) bool {
if t.Data[dexcomTaskRetryField] != nil {
count, ok := t.Data[dexcomTaskRetryField].(int)
Expand Down
14 changes: 2 additions & 12 deletions dexcom/fetch/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("Task", func() {
fetch.ErrorOrRetryTask(tsk, errors.New("some error"))
Expect(tsk.HasError()).To(Equal(false))
Expect(tsk.Data["retryCount"]).To(Equal(startCount + 1))
Expect(tsk.IsFailed()).To(Equal(false))
},
Entry("if zero retries", func() (*task.Task, int) {
retryCount := 0
Expand All @@ -57,6 +58,7 @@ var _ = Describe("Task", func() {
Expect(tsk.Data["retryCount"]).To(Equal(startCount))
fetch.ErrorOrRetryTask(tsk, errors.New("some error"))
Expect(tsk.HasError()).To(Equal(true))
Expect(tsk.IsFailed()).To(Equal(true))
},
Entry("when 3rd retry", func() (*task.Task, int) {
retryCount := 3
Expand Down Expand Up @@ -106,18 +108,6 @@ var _ = Describe("Task", func() {
})
})

Context("ResetTask", func() {
It("clears existing errors", func() {
tsk := getTask(3, true)
tsk.AppendError(errors.New("some error"))
Expect(tsk.HasError()).To(Equal(true))
Expect(tsk.Data["retryCount"]).To(Equal(3))
fetch.ResetTask(tsk)
Expect(tsk.HasError()).To(Equal(false))
Expect(tsk.Data["retryCount"]).To(Equal(0))
})
})

Context("NewTaskCreate", func() {
const providerID = "some-provider-id"
const sourceID = "some-source-id"
Expand Down

0 comments on commit c739eb2

Please sign in to comment.