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

schedule function emits with a parameter #320

Open
ImRodry opened this issue Dec 30, 2021 · 3 comments
Open

schedule function emits with a parameter #320

ImRodry opened this issue Dec 30, 2021 · 3 comments

Comments

@ImRodry
Copy link

ImRodry commented Dec 30, 2021

I installed the package today and I noticed that whenever the schedule function executes the function we pass as an argument, it receives 1 parameter which is a date corresponding to the time at which it was ran. This is not documented and is quite annoying when passing functions to be called, expecting there to be no parameters passed. This isn't in the @types/node-cron package either so I assume it is a bug that I would be happy to PR a fix for, if you'd like.
As a note, this issue is caused by this line:

exec = this._execution(now);

ImRodry added a commit to Hypixel-Translators/hypixel-translators-bot that referenced this issue Dec 30, 2021
This issue has been reported on their repo, see node-cron/node-cron#320
@merencia
Copy link
Member

Hi @ImRodry, yep, I've added this to make the date that the task started available inside the task... I don't know if this makes sense anymore...

However, there are two PR (#221 and #190) that are adding the received options on scheduling as an extra param to the task function. I think passing the options is a good thing to allows pass some data to the task, and I wonder about adding a startedAt to the options before pass that to the task function.

What do you think?

@ImRodry
Copy link
Author

ImRodry commented Jan 27, 2022

From those two PRs I prefer the implementation in #190 that allows you to choose which args get passed when executing, and I think that PR could just remove now as a whole since it will always be Date.now (or new Date() if you want the full object). That also has some limitations which is that the passed args are static, which makes it rather redundant. IMO the best option would be to call the function with no parameters, since whatever you were gonna pass can always be obtained in some other way since it’s static. That would require a semver major change of course, so let me know what you think of that.

@ashishvarman
Copy link

I too got into problems because of this behavior. Request to kindly remove the now argument from the called function.

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

No branches or pull requests

3 participants