Hacker News new | ask | show | jobs
by laserlight 1370 days ago
Hmm, this definition reads a bit wrong:

  @app.task((weekly.on("Mon") | weekly.on("Sat")) & time_of_day.after("10:00"))
  def do_twice_a_week_after_ten():
Expression reads Monday or Saturday, yet its meaning is Monday and Sunday according to function name.
2 comments

if you take it as a boolean test it makes sense. it will be true for any timepoint that is after ten and is either on monday or saturday
Yep, exactly. Rocketry works on conditions which are either true or false thus you need to give it a time range.

Points in time do not actually make much sense in terms of scheduling as nothing can be run exactly at specified point. There should always be some buffer of tolerance. I think Cron has a tolerance of a minute or so and in Rocketry the tolerance is made obvious and completely customized.

For those interested more about those two types of time conditions. "time_of_..." are conditions that check whether the current time is in the specified range. The "secondly", "minutely", "hourly", "daily" etc. also check that current time is as specified but also that the task did not yet run on the interval. By combining the two you can create quite complex scheduling strategies easily.

It would simplify things a little if the weekly.on accepted multiple days, so you could reduce it to one call:

    weekly.on("Mon", "Sat")
That's a great idea actually. Thanks, I think that should be pretty easy to do!
`|` is a bitwise-or in Python, not a boolean-or.
That's right, but it doesn't change how the expression is read.