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

fix: set runOnce when actual date is given to setTime #740

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

sheerlox
Copy link
Collaborator

@sheerlox sheerlox commented Oct 22, 2023

Description

initially, set the internal variable runOnce correctly when passing an actual date to setTime. previously this was only done in the constructor.

since it is only used in one place and as to limit this kind of error, I then removed the runOnce property completely (we now check directly if this.cronTime is a real date). we do not consider this a breaking change since it was not referenced in the API documentation).

Related Issue

Fixes #739.

Motivation and Context

Fixes an issue when after creating a job with a cron expression and using setTime with an actual date, the job attempts to run multiple times.

How Has This Been Tested?

added test case provided by #739's OP.

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).

@sheerlox sheerlox added the type:bug Bug reports and bug fixes label Oct 22, 2023
@sheerlox sheerlox self-assigned this Oct 22, 2023
@sheerlox sheerlox force-pushed the fix/739/setTime-actual-date-in-past branch from 1ec00ec to 7925e83 Compare October 22, 2023 14:16
Copy link

@lpgera lpgera left a comment

Choose a reason for hiding this comment

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

Thank you very much @sheerlox for the fix! I tested my use case with your fork and it perfectly resolves the issue.

@sheerlox sheerlox removed their assignment Oct 23, 2023
@sheerlox sheerlox merged commit ee54dd5 into kelektiv:main Oct 24, 2023
13 checks passed
@sheerlox sheerlox deleted the fix/739/setTime-actual-date-in-past branch October 24, 2023 00:04
ncb000gt pushed a commit that referenced this pull request Oct 24, 2023
## [3.1.4](v3.1.3...v3.1.4) (2023-10-24)

### 🐛 Bug Fixes

* run once when actual date is given to setTime ([#740](#740)) ([ee54dd5](ee54dd5))

### ⚙️ Continuous Integrations

* **action:** update actions/checkout action to v4 ([#735](#735)) ([144ba67](144ba67))

### ♻️ Chores

* **deps:** lock file maintenance ([#741](#741)) ([6d94742](6d94742))
* **deps:** update dependency [@types](https://github.com/types)/jest to v29.5.6 ([#736](#736)) ([57c0efa](57c0efa))
* **deps:** update dependency [@types](https://github.com/types)/node to v20.8.7 ([#737](#737)) ([21c4065](21c4065))
* **deps:** update dependency [@typescript-eslint](https://github.com/typescript-eslint)/eslint-plugin to v6.8.0 ([#734](#734)) ([12e7487](12e7487))
* **deps:** update tests ([#738](#738)) ([3815e2a](3815e2a))
@ncb000gt
Copy link
Member

🎉 This PR is included in version 3.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mirogajdos
Copy link

mirogajdos commented Oct 24, 2023

Hello. Using Cron together with with @nestjs/schedule and now my application won't build. Removal of property in PATCH release will ruin typechecks and builds for many people. It's definitely breaking change even if you didn't mention it in the docs as it was part of the type definitions. Now Job class is not backward compatible with previous versions. 😿

@sheerlox
Copy link
Collaborator Author

thanks for the heads up @extrememito, and sorry about the issue we caused in your build. not releasing these kinds of changes as breaking changes was probably okay for JS, but you're right that TS types actually are documentation on their own, and we should not break any public interfaces in patch or minor releases. we'll be more cautious about this in the future.

#751 is going to fix the issue once it's merged and released in 3.1.5.

as a side note, I'm curious what your setup looks like, because @nestjs/schedule uses pinned dependencies and didn't upgrade to 3.1.4 yet. would you mind expanding a bit on this?

@mirogajdos
Copy link

Thank you!! Sure. I'm running NX monorepo where some apps are using node-cron by itself and others via @nestjs/schedule. I'm using cron as described in this exmaple which requires importing CronJob class from node-cron and adding an instance into the registry. Therefore I have node-cron explicitly installed. I have also renovate bot setup to update Patch versions which bumped node-cron to 3.1.4 which resulted in:

TS2345: Argument of type 'import("/apps/node_modules/cron/dist/job").CronJob<null, null>' is not assignable to parameter of type 'import("/apps/node_modules/@nestjs/schedule/node_modules/cron/dist/job").CronJob<null, null>'.
  Property 'runOnce' is missing in type 'import("/apps/node_modules/cron/dist/job").CronJob<null, null>' but required in type 'import("/apps/node_modules/@nestjs/schedule/node_modules/cron/dist/job").CronJob<null, null>'.
    191 |       }
    192 |     })
  > 193 |     this.schedulerRegistry.addCronJob(expenseBlueprint.id, job)

@sheerlox
Copy link
Collaborator Author

@extrememito 3.1.5 is out, effectively restoring the runOnce property on CronJob! sorry again for the trouble.

sheerlox added a commit to sheerlox/node-cron that referenced this pull request Oct 29, 2023
sheerlox added a commit to sheerlox/node-cron that referenced this pull request Oct 29, 2023
sheerlox added a commit to sheerlox/node-cron that referenced this pull request Oct 29, 2023
sheerlox added a commit to sheerlox/node-cron that referenced this pull request Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released type:bug Bug reports and bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Job scheduled with setTime throws error instead of running
5 participants