Sanic could run configured schedule tasks. Users can define schedule as delayed or interval or cron-like pattern.
This is helpful when app need to update data, gather statistics, release unneeded resources automatically.
Using functions like asyncio.sleep(), an coroutine with an endless loop could check schedule periodically, and trigger functions that on schedule.
Multiple workers can be problem, when all worker trying to be scheduler at same time.
One solution is, giving every worker an id, and always using worker with id 0 to be the scheduler. This seems will work with sanic's builtin server, but as far as I know, gunicorn does not support worker with id.
Another solution is, to use some shared queues, like redis, to publish scheduled jobs. That seems fine, but it requires third party.
Any thoughts?
It doesn't have to be a builtin feature of Sanic, it'd be better to create a lib.
I think this would be more trouble than it's worth.
If you have your heart set out with running this in python you could use @dbader's library https://github.com/dbader/schedule and run it as a separate service that talks to your sanic application through maybe a private API?
Most helpful comment
It doesn't have to be a builtin feature of Sanic, it'd be better to create a lib.