@reboot nickname support
J0B10 opened this issue ยท 8 comments
First of all thanks for this great utility!
I'm currently implementing a scheduling for BetonQuest using a cron syntax (-> BetonQuest/BetonQuest#1885) and it saves a ton of work.
Only thing I'm still missing but really would love to implement is support to run stuff on startup using the @reboot
nickname just like it's known from the crontab syntax.
So I wonder what would be the best way to implement it. Is there any way I can create a CronDefinition that allows @reboot
or even add/check for custom nicknames?
If not is there anything like that planned or is this out of scope?
If this doesn't work out with cron-utils I have to implement that check separately but I would always prefer a native solution.
@J0B10 we are glad to hear cron-utils is helpful! ๐ How do you envision the support for the @reboot
nickname? We can think about supporting custom nicknames, but in this case, it won't be tied to a particular cron pattern for execution. Furthermore, how would you handle the reboot signalization? Any thoughts on this are appreciated, to design a solution.
Thanks for the quick response and thinking about making this a feature!
So it would be enough if in the cron definition one could allow specific nicks and then could have a check in the cron interface if the nick was present. Then all further implementation how such a reboot should be handled is up to the library user.
But I'm unsure how well that works with your current implementation as I haven't studied your code yet.
Till now it is a blackbox to me ๐
I'll see if I can have a look at your code this week and come back with a more refined idea that we can discuss.
So I had a further look. I'dd say a single cron should not only hold a map with CronFields, it should also store if a nickname was used.
A new instance could be either constructed with a list of fields or a nickname.
The cron interface should then provide a method to check if a specific nickname was used.
Nicknames should be a class, not an enum. The class should also provide a way to translate the nickname into a list/map of FieldExpressions so they can be translated to a traditonal cron.
For nicknames that can't be translated to a traditional cron (like @reboot
is) the list should be empty.
As such a nickname can not provide field expressions, the cron created from such nickname would just have an empty fields map.
The problem I see here is the following: It's impossible to translate such a cron to a different definition using a cron mapper as there is no equivalent expression in the other definition. And I think there is no way to solve this.
Also this would mean quite a few breaking changes. If you are fine with that I try if I can make this into a pull request.
@J0B10 thank you for the comments! ๐ We thought about nicknames as enums, given there are just a few keywords used across the multiple cron definitions and implementations. Therefore, it makes sense to restrict the nicknames to those options. We will check, and come back with a tentative implementation. Regarding the cron translation, if no conversion is possible, then we could throw an exception. Not all crons are "convertible" ๐ Thanks again!
@J0B10, we have implemented the feature! ๐ ๐ A release will follow soon! Thank you for pushing the boundaries of cron-utils ๐
Love it! โค๏ธ Thanks a lot for making this a thing! ๐
I will now look into updating our codebase to make use of the new features and run our tests against it.
So you can get a first feedback of how well it works.