-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: adds @cron task decorator #56
base: main
Are you sure you want to change the base?
Conversation
silverback/runner.py
Outdated
Execute scheduled cron tasks when their sequence comes up. | ||
""" | ||
while True: | ||
await asyncio.sleep(CRON_TICK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the cronjob is scheduled to be less than 15 seconds apart?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cron has a resolution of 1 minute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reduced his to 5 just to be a little more accurate
Can do like a drift sort of logic to make it loosely align with :00 +/- 1 sec (as clock drift may occur)
p.s. this website had some good test cases: https://crontab.guru/ |
You can do that with the `@cron` task decorator. | ||
|
||
```python | ||
@app.cron("* */1 * * *") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should actually test this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't even approve this because it's technically mine. May as well just have created a replacement PR for this one.
if current_time.second < CRON_CHECK_SECONDS: | ||
# Print out current time every minute | ||
logger.info(f"Current Time: {current_time}") | ||
# NOTE: In the absence of any cron jobs, we still print out the current time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: make this debug. bit verbose and not really useful unless you're debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually thinking this could be really useful to see for endusers, because they would have some live logging being created in scenarios where they are solely doing event log monitoring and nothing is really happening. Also very useful to know what the bot's local time is vs. the blockchain's, to see if there is some drift occuring.
What I did
Adds the
@cron
task decorator so we can execute arbitrary tasks according to a crontab schedule.How I did it
Adds an event loop to the runner that checks if cron tasks should be executes. If true, it will kiq the tasks off.
How to verify it
Checklist