Feature request: Pass task id to the handler
Opened this issue · 7 comments
Hi, thanks for the library, one really important feature is missing though. I have one global handler for all my cron tasks so I need to know which task is running. Would be great to have it as a parameter.
Thanks in advance!
Please let me know if you need a PR for that
I would appreciate a PR.
Please try to make it compatible with current API.
Thanks for the interest.
Have a look at the pull request that has not been merged yet. It might be a good starting point.
Yes, definitely. Instead of passing different function pointers, one handler can do all jobs by using task id. So, different software modules would have their single handlers.
Initially I implemented this, and snooze (schedule this again once off x seconds in the future), and once (seconds, callback) - set a callback once for the future - both of which just format a cron string. I also added a second signature create for the ID, and added default false to the isOneShot. In the end I used a container class rather than inheriting. I'll play with putting this all back in and generating a pull request.
Thank you scottp.
I would not like to overcomplicate the interface. Let us see what improvements are suggested overall.
It will be easier to decide if together with the improvements, use case examples are explicitly explained.
Totally - respect it is yours. I had a play last night. Got lambda passed in, and support older style c callbacks, and pass an integer (seconds from now) OR normal cron string. I defitely don't recommend putting it in as a pull request yet - not done a lot of testing, more ideas tasting. Alternatively I could easily adapt this to be CronAlarmsEx or simialr and inherit the class with additions, sort of meeting best of both worlds.
// No need to pass in false (defauilt) & example of lambda
Cron.create("25 * * * * *", [](CronID_t id) {
Serial.printf("test lambda Callback ID=%d\n", id);
});
// Create a once off task 15 seconds from now
Cron.create(15, [](CronID_t id) {
Serial.printf("test lambda Callback once off ID=%d\n", id);
});