-
Hello! Quick question here: Let's say I have a recurring task, Is that the expected behaviour? If it is, what is the recommended remedy if you want the recurring task to run as well?
And here is a code snippet: @app.task(name="geocode_address")
async def geocode_address(pk: int) -> None:
await asyncio.sleep(100) # Make sure it takes a long time
async def assign_addresses_to_geocode() -> None:
async for i in range(1, 100):
await geocode_address.defer_async(pk=i)
@app.periodic(cron="*/5 * * * *")
@app.task(name="recurring_task")
async def recurring_task(timestamp: int) -> None:
logger.info("Starting: recurring_task")
await assign_addresses_to_geocode()
logger.info("Completed: recurring_task") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The general rule is that when a worker decides what's the next job to tackle, it selects, among the available ones, the one with the lowest (incremental) id. This means if you have 100 long tasks deferred and one short task waiting after that, in general it will get executed after the 100 tasks (namely, there's no way to tell if a task will be long or short, and we try to have tasks be executed in a somewhat predictable order). Now there are still some things worth mentioning. Before diving in the details, there's one point that needs addressing. I might be wrong, but if you create 100 tasks that all take 100 seconds, I see 3 possible outcomes:
Here are some things that may help situation 3 (and potentially situation 2):
If you think with the current rules, the way it works is wrong, or you think there should be an obvious way to solve your problem, it might be interesting (but I'm not spending a lot of time, if any, developing new features for this lib so any evolution needs to come from other contributors) |
Beta Was this translation helpful? Give feedback.
The general rule is that when a worker decides what's the next job to tackle, it selects, among the available ones, the one with the lowest (incremental) id. This means if you have 100 long tasks deferred and one short task waiting after that, in general it will get executed after the 100 tasks (namely, there's no way to tell if a task will be long or short, and we try to have tasks be executed in a somewhat predictable order).
Now there are still some things worth mentioning. Before diving in the details, there's one point that needs addressing. I might be wrong, but if you create 100 tasks that all take 100 seconds, I see 3 possible outcomes: