Frequency of task start every 10 seconds #245
Replies: 4 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: importasynciofromtaskiqimportTaskiqSchedulerfromtaskiq.schedule_sourcesimportLabelScheduleSourcefromtaskiq_redisimportListQueueBrokerbroker=ListQueueBroker("redis://localhost")
scheduler=TaskiqScheduler(broker, [LabelScheduleSource(broker)])
@broker.task(schedule=[ {"cron": "* * * * *", } ],)asyncdefmytask(wait_time: int):
print("waiting", wait_time)
foriinrange(5):
awaitasyncio.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. defmy_target():
print("Do the job")
asyncdefmytask(wait_time: int):
print("waiting", wait_time)
foriinrange(5):
awaitasyncio.sleep(10*i)
asyncio.create_task(my_target()) |
Thank you very much! |
Is this still the goto solution or was sup-minutes scheduling added? |
https://taskiq-python.github.io/available-components/schedule-sources.html#labelschedulesource you can use "interval": None, # type: int | timedelta, either cron, interval or time should be specified. |
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.
All reactions