Help needed with AfterJobRunsWithError configuration #795
-
Hi, I have the following job definition: _, err := scheduler.NewJob(
gocron.DurationJob(interval),
gocron.NewTask(func() {
handler.RunReceivableWindowsWorker(ctx, maxWindowSize)
}),
gocron.WithEventListeners(
gocron.AfterJobRunsWithError(func(jobID uuid.UUID, jobName string, err error) {
log.Error().Err(err).Msg("Receivable Windows Worker failed execution.")
}),
),
gocron.WithSingletonMode(gocron.LimitModeReschedule),
) I'm wondering why the Cheers, |
Beta Was this translation helpful? Give feedback.
Answered by
JohnRoesler
Nov 5, 2024
Replies: 1 comment 2 replies
-
Hi @lays147 You'll need to capture and return the error from the handler, similar to this test https://github.com/go-co-op/gocron/blob/v2/scheduler_test.go#L1778-L1785 Assuming _, err := scheduler.NewJob(
gocron.DurationJob(interval),
- gocron.NewTask(func() {
+ gocron.NewTask(func() error {
- handler.RunReceivableWindowsWorker(ctx, maxWindowSize)
+ return handler.RunReceivableWindowsWorker(ctx, maxWindowSize)
}),
gocron.WithEventListeners(
gocron.AfterJobRunsWithError(func(jobID uuid.UUID, jobName string, err error) {
log.Error().Err(err).Msg("Receivable Windows Worker failed execution.")
}),
),
gocron.WithSingletonMode(gocron.LimitModeReschedule),
) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
lays147
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @lays147
You'll need to capture and return the error from the handler, similar to this test https://github.com/go-co-op/gocron/blob/v2/scheduler_test.go#L1778-L1785
Assuming
handler.RunReceivableWindowsWorker(ctx, maxWindowSize)
returns only 1 argument, an error, you could do