Open Murplugg opened 2 years ago
Thanks for the thorough and well-thought issue! Especially your proposal for the condition syntax looks awesome: clean and understandable. This was very insigtful.
I'm pretty tired at the moment and probably need to reread what you said later but I personally think Rocketry should support randomized runs. I'm currently doing some fixes to the parametrization so that it supports setting parameters for a manual run. After that I probably have time to investigate this more.
You said this already but to recap for myself, there are at least two related needs:
I think there are three things that must be defined:
What comes to the implementation, I think this could be done in a way that the time period is simply just dynamic. Basically the problem could be solved in a way that we utilize TaskExecutable
or TaskRunnable
classes to handle checking if the task has finished/runned and then we simply pass a period that changes randomly.
Let's take an example, like this daily at 07:00 +/- 2 hours
. This can be:
05:00 - 10:00
07:00 - 08:00
Note that at
basically means one full child unit. For daily
it means one hour, for hourly
it means one minute etc. So basically the start is something in between 05:00
and 07:00
and the end is something in between 08:00
and 10:00
. We just need to generate random values between these, then create a period out of it (simple) and pass that to TaskExecutable
/TaskRunnable
. Then we also need to do the previous again after this period is over. Doesn't sound too bad and actually something that fits rather nicely to what we already have. I think the units (ie. +/- 2 hours
) should always just be smaller than the period we work with: daily supports +/- 2 hours
, +/- 2 minutes
, +/- 2 seconds
etc. Possibly at first we could make it support just the resolution which is already stored in the periods (ie. hour
for daily
).
I'll revisit this latest in the weekend as, as I said, I probably should be sleeping already. Thanks again for the effort you put for writing the issue.
Is your feature request related to a problem? Please describe. Hi! I'm thinking of using this library as part of a scheduler / manager to automate various tasks including web-scraping and running parts of a multi-agent system. I have some tasks that either shouldn't or don't need to be run at exactly defined moments (e.g. web-scrapers and randomized load balancing) and it would be very helpful to be able to set a spread or error bar to a time / trigger condition. I.e. set some acceptable leeway that's non-fixed.
Describe the solution you'd like Specifically I want to introduce non-fixed acceptable leeway -- randomly sampled error from a range -- to defined start- and end-times in a way that has the errors change each time a condition is evaluated (not set the error once and re-use it). This should be handled under the hood by Rocketry to minimize boilerplate code / code complexity.
In practice what I envision is one or more of the following extensions:
@app.task("daily after 07:00 +/- 10 minutes")
and"daily after 07:00 +/- 2 hours
. Would apply to the Condition API as well:every("10 seconds +/- 2 seconds")
.spread
orerror
attribute to the members ofrocketry.cond
(after, between, on, ...).Choice of sampling method used to set the final offset can in theory also be a user choice but I'm not sure where that parameter is best defined -- it adds more complexity to the language syntax. Passed as an argument or maybe set on the
Session
beforehand might be better options. I see two viable sampling methods: Uniform random and Gaussian.Then there's a question of the spread size. It makes no sense to say "+/- 1 day" or "+/- 7 hours" in the above examples, so there should perhaps be some constraint handling in place. Exactly which ones is unclear.
Describe alternatives you've considered I have considered dynamically setting or adjusting times on a per run basis using my own code external to Rocketry. Functionally this will likely be fine but it adds complexity to my code and I believe others might enjoy this feature too. It's unclear to me how I can implement variation on the timing in a way that's handled under the hood by Rocketry. I know the request might seem odd in the face of Rocketry trying to be as precise and timely as possible but I like this library and I see my suggestions here as an extension to fill a niche.
Additional context I had a look at https://github.com/Miksus/rocketry/issues/89#issuecomment-1234689610 and like the idea presented there but as far as I see that fulfills a different need (i.e. setting a probability of running a task at all, time still being exact). I would love to provide a similarly small example but haven't yet figured out the internals of Rocketry to do so.