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

feat: error handling on ticks #861

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

JosephVoid
Copy link

@JosephVoid JosephVoid commented Mar 3, 2024

Description

I've added an error handling method in the CronJob class and added it to the constructors parameters. This error handling method will be called if any exception is thrown from the onTick method. Also added two new tests to confirm that it works.

Related Issue

Closes #426.

Motivation and Context

If any kind of exception occurs from the onTick method the whole process stops currently. To solve this, this feature will allow users to pass their own error handler when exceptions occur.

How Has This Been Tested?

Added two new test cases called should catch errors if errorhandler is provided & should throw errors if errorhandler is NOT provided

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • If my change introduces a breaking change, I have added a ! after the type/scope in the title (see the Conventional Commits standard).

+ added error handling function param on a new constructor
+ added the function param on the static `from` method
+ caught the errors in the callback method
+ removed `@ts-expect-error line` bc it was throwing error itself
@JosephVoid JosephVoid changed the title feat: error handling on job.start() feat(error-handle): error handling on job.start() Mar 3, 2024
@JosephVoid JosephVoid changed the title feat(error-handle): error handling on job.start() feat: error handling on job.start() Mar 3, 2024
@JosephVoid JosephVoid marked this pull request as ready for review March 3, 2024 09:45
src/types/cron.types.ts Outdated Show resolved Hide resolved
tests/cron.test.ts Outdated Show resolved Hide resolved
src/job.ts Show resolved Hide resolved
src/job.ts Outdated Show resolved Hide resolved
src/job.ts Outdated Show resolved Hide resolved
+ Instead of a new constructor, I added the `errorHandler` on every other constructor
+ removed the superflous if checks
+ added `errorHandler` on every `return new CronJob`
@JosephVoid
Copy link
Author

Hey @sheerlox,

Thanks for the review. I've incorporated all the suggestions.

sheerlox
sheerlox previously approved these changes Mar 8, 2024
Copy link
Collaborator

@sheerlox sheerlox left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your contribution @JosephVoid 🙌

@sheerlox sheerlox requested a review from intcreator March 8, 2024 09:13
@sheerlox sheerlox force-pushed the feature/error-handling branch from b3902a9 to f13aba2 Compare March 8, 2024 09:19
@sheerlox sheerlox changed the title feat: error handling on job.start() feat: error handling on ticks Mar 8, 2024
@MetlHedd
Copy link

Hey, any news on this being merged into main?

@intcreator
Copy link
Collaborator

hello, I'm currently working on the waitForCompletion PR as well as fixing the merge conflicts in this PR from that. I plan on reviewing this next

@intcreator
Copy link
Collaborator

intcreator commented Dec 14, 2024

I submitted a PR to this branch to fix the merge conflicts. @JosephVoid if you can merge it then this PR will be ready for a final review

@intcreator
Copy link
Collaborator

actually I think I submitted the PR to the wrong branch. new one here. if it works then it should show this merge conflict as fixed

@sheerlox
Copy link
Collaborator

Excellent work @JosephVoid, thank you for taking on this feature request! Thanks @intcreator also for taking over the review 😄

@sheerlox
Copy link
Collaborator

Looks like the tests aren't passing, if someone wants to look into it so we can merge!

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.

error handling
4 participants