Reputation: 937
I'm using apscheduler
to deal with several jobs that run asyncronously. One of those tasks requests some payload from an API every second. Due to how the network works the job can await
for 10 seconds before being aborted. While the job is being run apscheduler
displays several warnings in the log telling me that the maximum number of running instances was reached, adding more instances would not make the job run faster (or better).
How do I tell apscheduler
to stop logging that type of message for that job?
The following code reproduces the problem.
import asyncio
import logging
from apscheduler.executors.pool import ThreadPoolExecutor
from apscheduler.schedulers.asyncio import AsyncIOScheduler
async def my_slow_job():
await asyncio.sleep(10)
async def main():
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
scheduler = AsyncIOScheduler(
executor=ThreadPoolExecutor(),
job_defaults={'trigger': 'interval', 'seconds': 1, 'max_instances': 1}
)
scheduler.add_job(my_slow_job, 'interval')
scheduler.start()
while True:
await asyncio.sleep(1000)
if __name__ == "__main__":
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit, asyncio.exceptions.CancelledError):
logging.warning("Shutting down by user request")
Upvotes: 0
Views: 216