-
I'm looking to schedule periodic tasks on workers and thus far it looks like there's not a canonical way to do this. My current thinking is to combine import asyncio
from apscheduler.schedulers.background import BackgroundScheduler as APScheduler
from apscheduler.triggers.interval import IntervalTrigger
async def main():
apscheduler = APScheduler()
apscheduler.add_job(lambda: print("ping"), trigger=IntervalTrigger(seconds=1))
apscheduler.start()
async with Scheduler() as scheduler:
print(scheduler.identity())
await asyncio.sleep(60)
asyncio.run(main()) This works but it feels like a bit of a hack since now I have to run this script instead of just running For some more context I have a Tornado web app and want to use Dask to offload some tasks to. Currently I have just a single server process so I could kick off the periodic tasks from there. However I'd like to have the option to add additional server processes in the future so it would make more sense to have the scheduler itself launching these tasks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Indeed, the scheduler as a class is not documented. It is something which changes fairly frequently and I would advise caution to rely on any specifics which are not advertised otherwise as part of the API
I would go for a tornado PeriodicCallback which we are using in distributed all over the place. To start this, I suggest to implement a plugin for this, which is our way to offer users a stable method to hook into what is going on underneath. There are a few hooks for specific events but if it is just about spawning a PC, you can just do this upon plugin initialisation and don't need to implement any further methods. If the CLI preload to start the plugin does not work for you, there is also a way to do this rather dynamically, see https://distributed.dask.org/en/latest/api.html#distributed.Client.register_worker_plugin |
Beta Was this translation helpful? Give feedback.
Indeed, the scheduler as a class is not documented. It is something which changes fairly frequently and I would advise caution to rely on any specifics which are not advertised otherwise as part of the API
I would go for a tornado PeriodicCallback which we are using in distributed all over the place.
To start this, I suggest to implement a plugin for this, which is our way to offer users a stable method…