Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AfterJobRunsWithPanic #733

Merged
merged 8 commits into from
Jun 20, 2024

Conversation

trungdlp-wolffun
Copy link
Contributor

What does this do?

Which issue(s) does this PR fix/relate to?

Resolves #732

List any changes that modify/break current functionality

Have you included tests for your changes?

Yes

Did you document any new/modified functionality?

  • Updated example_test.go
  • Updated README.md

Notes

Copy link
Contributor

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @trungdlp-wolffun thanks for working on this!

I think the concept would fit nicely as another EventListener. EventListeners can be added to a single Job using WithEventListeners, as well as for the entire scheduler using WithGlobalJobOptions.

You could model it after AfterJobRunsWithError, but call it AfterJobRunsWithPanic.

@trungdlp-wolffun trungdlp-wolffun changed the title Add executor option for panic handler Add AfterJobRunsWithPanic Jun 19, 2024
@trungdlp-wolffun
Copy link
Contributor Author

@JohnRoesler I changed it to the EventListener: AfterJobRunsWithPanic, you can review it now

_ = callJobFuncWithParams(j.afterJobRunsWithPanic, j.id, j.name, recoverData)

// if panic is occurred, we should return an error
err = ErrPanicRecovered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this error ever readable by the caller? Seems ineffectual. But I could be wrong 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller can catch this error via an EventListener

WithEventListeners(
  AfterJobRunsWithError(
    func(jobID uuid.UUID, jobName string, err error) {
      if errors.Is(err, gocron.ErrPanicRecovered) {
         // ....
      }
    },
  ),
),

@JohnRoesler JohnRoesler merged commit 399ac28 into go-co-op:v2 Jun 20, 2024
4 checks passed
@trungdlp-wolffun trungdlp-wolffun deleted the feature/panic_recover branch June 21, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] - no mechanism to handle panic in jobs for v2
2 participants