-
I want to write a custom APScheduler scheduler. I want the scheduler to only have a single instance of the scheduler actually "started" to not execute tasks multiple times, if I have multiple workers. My current approach would be to use a PostgreSQL advisory lock or something similar. Is there a way to identify workers by some kind of unique id, from within python? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I managed to get the IDs like this but I think it will not help me solve my underlying issue the way i thought it would and I am going in another direction and will start the apschedule "beside" granian during my granian startup script. g: MTServer | MPServer = Granian(
"core", interface=Interfaces.WSGI, address=address, port=port, log_level=loglevel, workers=workers, respawn_failed_workers=True
)
spawn_target = g._spawn_wsgi_worker
target_loader = partial(app_loader, g.target)
g.startup(spawn_target, target_loader)
worker_ids = [w._id() for w in g.wrks]
print(f"Workers: {worker_ids}")
g._serve_loop(spawn_target, target_loader)
g.shutdown() |
Beta Was this translation helpful? Give feedback.
-
Just for documentation if someone finds this: I spent a lot of time trying to get APScheduler to use the granian asynicio event loop with an AsyncIOScheduler and after taking a deep dive into the APScheduler codebase and trying I am pretty confident this doesnt work with APScheduler 3. Therefore, I am abandoning this approach. I think the best chance to get this running the way I intended will be waiting for APScheduler 4 |
Beta Was this translation helpful? Give feedback.
This is the way.