Frequency of task start every 10 seconds #245
Unanswered
iPatrushevSergey
asked this question in
Q&A
Replies: 2 comments
-
Currently you can create it, but taskiq scheduler has quantization of minutes. Which means that you cannot start tasks every n seconds, where n is less than 60. To solve this issue, I would suggest this solution: import asyncio
from taskiq import TaskiqScheduler
from taskiq.schedule_sources import LabelScheduleSource
from taskiq_redis import ListQueueBroker
broker = ListQueueBroker("redis://localhost")
scheduler = TaskiqScheduler(broker, [LabelScheduleSource(broker)])
@broker.task(
schedule=[
{
"cron": "* * * * *",
}
],
)
async def mytask(wait_time: int):
print("waiting", wait_time)
for i in range(5):
await asyncio.sleep(10 * i)
print("Do the job") This task is going to be executed every minute and will run the action every 10 seconds. If you want to be more precise about when function are executed, you can run your target function as an async task. def my_target():
print("Do the job")
async def mytask(wait_time: int):
print("waiting", wait_time)
for i in range(5):
await asyncio.sleep(10 * i)
asyncio.create_task(my_target()) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you very much! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to set the task execution frequency in seconds in schedule? For example, every 10 seconds.
Beta Was this translation helpful? Give feedback.
All reactions