Open faulander opened 1 year ago
This works:
@app.task(
(
(
time_of_week.on("Mon")
| time_of_week.on("Tue")
| time_of_week.on("Wed")
| time_of_week.on("Thu")
| time_of_week.on("Fri")
)
& time_of_day.between("08:00", "20:00")
)
& every("1 hours")
)
is there an easier way to write: Run this task every x on weekdays between 08:00 and 20:00 ?
@faulander You can try doing it this way. Write a custom app condition, which only schedules a function to run on Weekdays. Then use the condition while scheduling the task.
from rocketry import Rocketry
from rocketry.conds import time_of_day, every
from datetime import datetime
app = Rocketry()
WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
@app.cond()
def is_week_day():
day = datetime.now().strftime("%A")
if day in WEEKDAYS:
return True
return False
@app.task(is_week_day & time_of_day.between("8:00", "20:00") & every("1 hours"))
def do_things():
...
if __name__ == "__main__":
app.run()
@Miksus I think we can close this issue.
Describe the bug Tasks with this task definition only run once
Expected behavior task should run every day, every 10 minutes during 8am and 8pm
Desktop (please complete the following information):