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

Commit

Permalink
More improvements to reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Sep 20, 2021
1 parent eefa414 commit 3927063
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
11 changes: 11 additions & 0 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"time"

"github.com/getsentry/sentry-go"
"github.com/monetr/rest-api/pkg/internal/platypus"

"github.com/go-pg/pg/v10"
Expand Down Expand Up @@ -234,3 +235,13 @@ func (j *jobManagerBase) Close() error {
j.work.Stop()
return nil
}

func (j *jobManagerBase) recover(ctx context.Context) {
if hub := sentry.GetHubFromContext(ctx); hub != nil {
if err := recover(); err != nil {
hub.RecoverWithContext(ctx, err)
}
} else {
sentry.RecoverWithContext(ctx)
}
}
11 changes: 7 additions & 4 deletions pkg/jobs/pull_account_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ func (j *jobManagerBase) enqueuePullAccountBalances(job *work.Job) error {
}

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

defer j.recover(span.Context())

defer func() {
if err := recover(); err != nil {
sentry.CaptureException(errors.Errorf("pull account balances failure: %+v", err))
}
}()

hub := sentry.CurrentHub().Clone()
ctx := sentry.SetHubOnContext(context.Background(), hub)
span := sentry.StartSpan(ctx, "Job", sentry.TransactionName("Pull Account Balances"))
defer span.Finish()

start := time.Now()
log := j.getLogForJob(job)
Expand Down
15 changes: 6 additions & 9 deletions pkg/jobs/pull_latest_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,17 @@ func (j *jobManagerBase) enqueuePullLatestTransactions(job *work.Job) error {
}

func (j *jobManagerBase) pullLatestTransactions(job *work.Job) (err error) {
defer func() {
if err := recover(); err != nil {
sentry.CaptureException(errors.Errorf("pull latest transactions failure: %+v", err))
}
}()

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

hub := sentry.CurrentHub().Clone()
ctx := sentry.SetHubOnContext(context.Background(), hub)
span := sentry.StartSpan(ctx, "Job", sentry.TransactionName("Pull Latest Transactions"))
defer span.Finish()

defer j.recover(span.Context())

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


defer func() {
if err != nil {
hub.CaptureException(err)
Expand Down
8 changes: 2 additions & 6 deletions pkg/jobs/transactions_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ func (j *jobManagerBase) TriggerRemoveTransactions(accountId, linkId uint64, rem
}

func (j *jobManagerBase) removeTransactions(job *work.Job) error {
defer func() {
if err := recover(); err != nil {
sentry.CaptureException(errors.Errorf("remove transactions failure: %+v", err))
}
}()

hub := sentry.CurrentHub().Clone()
ctx := sentry.SetHubOnContext(context.Background(), hub)
span := sentry.StartSpan(ctx, "Job", sentry.TransactionName("Remove Transactions"))
defer span.Finish()

defer j.recover(span.Context())

log := j.getLogForJob(job)

transactionIds := strings.Split(job.ArgString("removedTransactions"), ",")
Expand Down

0 comments on commit 3927063

Please sign in to comment.