Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@app.task(daily.between("08:00", "20:00") & every("10 minutes")) #192

Open
faulander opened this issue Feb 9, 2023 · 3 comments
Open

@app.task(daily.between("08:00", "20:00") & every("10 minutes")) #192

faulander opened this issue Feb 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@faulander
Copy link

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):

  • OS: Ubuntu 20
  • Python 3.8
@faulander faulander added the bug Something isn't working label Feb 9, 2023
@faulander
Copy link
Author

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 ?

@rohansh-tty
Copy link
Contributor

@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()

@rohansh-tty
Copy link
Contributor

@Miksus I think we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants