From a6e66189d3c9a46a43be1cca7b871dd676383daa Mon Sep 17 00:00:00 2001 From: Darin Krauss Date: Wed, 7 Feb 2018 12:33:10 -0800 Subject: [PATCH] Avoid time period when Dexcom API refresh token failures occur --- dexcom/fetch/runner.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dexcom/fetch/runner.go b/dexcom/fetch/runner.go index 37b5fba29..9e2f6ce9b 100644 --- a/dexcom/fetch/runner.go +++ b/dexcom/fetch/runner.go @@ -95,17 +95,28 @@ func (r *Runner) Run(ctx context.Context, tsk *task.Task) { ctx = log.NewContextWithLogger(ctx, r.Logger()) - tsk.ClearError() - - if serverSessionToken, sErr := r.AuthClient().ServerSessionToken(); sErr != nil { - tsk.AppendError(errors.Wrap(sErr, "unable to get server session token")) + // HACK: Skip 2:45am - 3:45am PST to avoid intermittent refresh token failure due to Dexcom backups + var skipToAvoidDexcomBackup bool + if location, err := time.LoadLocation("America/Los_Angeles"); err != nil { + r.Logger().WithError(err).Warn("Unable to load location to detect Dexcom backup") } else { - ctx = auth.NewContextWithServerSessionToken(ctx, serverSessionToken) + tm := time.Now().In(location).Format("15:04:05") + skipToAvoidDexcomBackup = (tm >= "02:45:00") && (tm < "03:45:00") + } + + if !skipToAvoidDexcomBackup { + tsk.ClearError() - if taskRunner, tErr := NewTaskRunner(r, tsk); tErr != nil { - tsk.AppendError(errors.Wrap(tErr, "unable to create task runner")) - } else if tErr = taskRunner.Run(ctx); tErr != nil { - tsk.AppendError(errors.Wrap(tErr, "unable to run task runner")) + if serverSessionToken, sErr := r.AuthClient().ServerSessionToken(); sErr != nil { + tsk.AppendError(errors.Wrap(sErr, "unable to get server session token")) + } else { + ctx = auth.NewContextWithServerSessionToken(ctx, serverSessionToken) + + if taskRunner, tErr := NewTaskRunner(r, tsk); tErr != nil { + tsk.AppendError(errors.Wrap(tErr, "unable to create task runner")) + } else if tErr = taskRunner.Run(ctx); tErr != nil { + tsk.AppendError(errors.Wrap(tErr, "unable to run task runner")) + } } }