asyncio.py 883 B

1234567891011121314151617181920212223242526272829
  1. from __future__ import absolute_import
  2. import sys
  3. from apscheduler.executors.base import BaseExecutor, run_job
  4. class AsyncIOExecutor(BaseExecutor):
  5. """
  6. Runs jobs in the default executor of the event loop.
  7. Plugin alias: ``asyncio``
  8. """
  9. def start(self, scheduler, alias):
  10. super(AsyncIOExecutor, self).start(scheduler, alias)
  11. self._eventloop = scheduler._eventloop
  12. def _do_submit_job(self, job, run_times):
  13. def callback(f):
  14. try:
  15. events = f.result()
  16. except:
  17. self._run_job_error(job.id, *sys.exc_info()[1:])
  18. else:
  19. self._run_job_success(job.id, events)
  20. f = self._eventloop.run_in_executor(None, run_job, job, job._jobstore_alias, run_times,
  21. self._logger.name)
  22. f.add_done_callback(callback)