Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Adding stuff around errors in jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Jun 14, 2021
1 parent 540c0c7 commit d69b64e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/jobs/pull_account_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (j *jobManagerBase) pullAccountBalances(job *work.Job) error {
return err
}

log = log.WithField("linkId", link.LinkId)

if link.PlaidLink == nil {
err = errors.Errorf("cannot pull account balanaces for link without plaid info")
log.WithError(err).Errorf("failed to pull balances")
Expand Down
25 changes: 15 additions & 10 deletions pkg/jobs/pull_latest_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ func (j *jobManagerBase) enqueuePullLatestTransactions(job *work.Job) error {
}

func (j *jobManagerBase) pullLatestTransactions(job *work.Job) error {
hub := sentry.CurrentHub().Clone()
ctx := sentry.SetHubOnContext(context.Background(), hub)
span := sentry.StartSpan(ctx, "Job", sentry.TransactionName("Pull Latest Transactions"))
defer span.Finish()

startTime := time.Now()
log := j.getLogForJob(job)
log.Infof("pulling account balances")

Expand All @@ -102,6 +96,18 @@ func (j *jobManagerBase) pullLatestTransactions(job *work.Job) error {
return err
}

hub := sentry.CurrentHub().Clone()
hub.WithScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{
ID: strconv.FormatUint(accountId, 10),
})
})
ctx := sentry.SetHubOnContext(context.Background(), hub)
span := sentry.StartSpan(ctx, "Job", sentry.TransactionName("Pull Latest Transactions"))
defer span.Finish()

startTime := time.Now()

defer func() {
if j.stats != nil {
j.stats.JobFinished(PullAccountBalances, accountId, startTime)
Expand Down Expand Up @@ -131,6 +137,8 @@ func (j *jobManagerBase) pullLatestTransactions(job *work.Job) error {
return err
}

log = log.WithField("linkId", link.LinkId)

if link.PlaidLink == nil {
err = errors.Errorf("cannot pull account balanaces for link without plaid info")
log.WithError(err).Errorf("failed to pull transactions")
Expand Down Expand Up @@ -190,15 +198,12 @@ func (j *jobManagerBase) pullLatestTransactions(job *work.Job) error {
// for this right now.
return nil
default:
log.Warnf("unknown error type from Plaid client: %T", plaidErr)
log.WithError(err).Warnf("unknown error type from Plaid client: %T", plaidErr)
}

return errors.Wrap(err, "failed to retrieve transactions from plaid")
}

// TODO Are plaid transaction Ids unique per link, or per bank account?
// If they are not then this could cause an issue where a user's checking transaction has the same Id as a
// savings account transaction but under the same link. Causing the transaction to get updated improperly.
plaidTransactionIds := make([]string, len(transactions))
for i, transaction := range transactions {
plaidTransactionIds[i] = transaction.ID
Expand Down
2 changes: 2 additions & 0 deletions pkg/jobs/transactions_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (j *jobManagerBase) removeTransactions(job *work.Job) error {
return err
}

log = log.WithField("linkId", link.LinkId)

if link.PlaidLink == nil {
err = errors.Errorf("cannot pull account balanaces for link without plaid info")
log.WithError(err).Errorf("failed to pull transactions")
Expand Down

0 comments on commit d69b64e

Please sign in to comment.