Skip to content

Help needed with AfterJobRunsWithError configuration #795

Answered by JohnRoesler
lays147 asked this question in Q&A
Discussion options

You must be logged in to vote

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

_, 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 Worke…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lays147
Comment options

@JohnRoesler
Comment options

Answer selected by lays147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants