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

Commit

Permalink
Jobs are crashing, trying to diagnose.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Sep 20, 2021
1 parent 5f4b832 commit eefa414
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
8 changes: 5 additions & 3 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package jobs

import (
"context"
"github.com/monetr/rest-api/pkg/internal/platypus"
"math"
"time"

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

"github.com/go-pg/pg/v10"
"github.com/gocraft/work"
"github.com/gomodule/redigo/redis"
Expand Down Expand Up @@ -104,8 +105,9 @@ func NewJobManager(
manager.work.PeriodicallyEnqueue("0 0 * * * *", EnqueueProcessFundingSchedules)

// Once a day. But also can be triggered by a webhook.
manager.work.PeriodicallyEnqueue("0 0 0 * * *", EnqueuePullAccountBalances)
manager.work.PeriodicallyEnqueue("0 0 0 * * *", EnqueuePullLatestTransactions)
// Once A day. 0 0 0 * * *
manager.work.PeriodicallyEnqueue("0 0 * * * *", EnqueuePullAccountBalances)
manager.work.PeriodicallyEnqueue("0 0 * * * *", EnqueuePullLatestTransactions)
//manager.work.PeriodicallyEnqueue("0 0 0 * * *", UpdateInstitutions)

manager.work.Start()
Expand Down
11 changes: 9 additions & 2 deletions pkg/jobs/pull_account_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package jobs
import (
"context"
"fmt"
"strconv"
"time"

"github.com/getsentry/sentry-go"
"github.com/monetr/rest-api/pkg/crumbs"
"github.com/sirupsen/logrus"
"strconv"
"time"

"github.com/gocraft/work"
"github.com/monetr/rest-api/pkg/models"
Expand Down Expand Up @@ -80,6 +81,12 @@ func (j *jobManagerBase) enqueuePullAccountBalances(job *work.Job) error {
}

func (j *jobManagerBase) pullAccountBalances(job *work.Job) (err error) {
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"))
Expand Down
9 changes: 8 additions & 1 deletion pkg/jobs/pull_latest_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package jobs
import (
"context"
"fmt"
"github.com/monetr/rest-api/pkg/crumbs"
"strconv"
"time"

"github.com/monetr/rest-api/pkg/crumbs"

"github.com/getsentry/sentry-go"
"github.com/gocraft/work"
"github.com/monetr/rest-api/pkg/internal/myownsanity"
Expand Down Expand Up @@ -87,6 +88,12 @@ 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")

Expand Down
13 changes: 10 additions & 3 deletions pkg/jobs/transactions_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package jobs
import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/getsentry/sentry-go"
"github.com/gocraft/work"
"github.com/monetr/rest-api/pkg/internal/myownsanity"
"github.com/monetr/rest-api/pkg/repository"
"github.com/pkg/errors"
"strconv"
"strings"
"time"
)

const (
Expand All @@ -31,6 +32,12 @@ 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"))
Expand Down

0 comments on commit eefa414

Please sign in to comment.