Frequency of task start every 10 seconds #245
Replies: 3 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.
-
Thank you very much! |
Beta Was this translation helpful? Give feedback.
-
Is this still the goto solution or was sup-minutes scheduling added? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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