mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-01-07 11:40:01 -08:00
ded93ef2f5
* Bump apscheduler from 3.9.1.post1 to 3.10.0 Bumps [apscheduler](https://github.com/agronholm/apscheduler) from 3.9.1.post1 to 3.10.0. - [Release notes](https://github.com/agronholm/apscheduler/releases) - [Changelog](https://github.com/agronholm/apscheduler/blob/3.10.0/docs/versionhistory.rst) - [Commits](https://github.com/agronholm/apscheduler/compare/3.9.1.post1...3.10.0) --- updated-dependencies: - dependency-name: apscheduler dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update apscheduler==3.10.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from __future__ import absolute_import
|
|
|
|
import sys
|
|
|
|
from apscheduler.executors.base import BaseExecutor, run_job
|
|
from apscheduler.executors.base_py3 import run_coroutine_job
|
|
from apscheduler.util import iscoroutinefunction_partial
|
|
|
|
|
|
class AsyncIOExecutor(BaseExecutor):
|
|
"""
|
|
Runs jobs in the default executor of the event loop.
|
|
|
|
If the job function is a native coroutine function, it is scheduled to be run directly in the
|
|
event loop as soon as possible. All other functions are run in the event loop's default
|
|
executor which is usually a thread pool.
|
|
|
|
Plugin alias: ``asyncio``
|
|
"""
|
|
|
|
def start(self, scheduler, alias):
|
|
super(AsyncIOExecutor, self).start(scheduler, alias)
|
|
self._eventloop = scheduler._eventloop
|
|
self._pending_futures = set()
|
|
|
|
def shutdown(self, wait=True):
|
|
# There is no way to honor wait=True without converting this method into a coroutine method
|
|
for f in self._pending_futures:
|
|
if not f.done():
|
|
f.cancel()
|
|
|
|
self._pending_futures.clear()
|
|
|
|
def _do_submit_job(self, job, run_times):
|
|
def callback(f):
|
|
self._pending_futures.discard(f)
|
|
try:
|
|
events = f.result()
|
|
except BaseException:
|
|
self._run_job_error(job.id, *sys.exc_info()[1:])
|
|
else:
|
|
self._run_job_success(job.id, events)
|
|
|
|
if iscoroutinefunction_partial(job.func):
|
|
coro = run_coroutine_job(job, job._jobstore_alias, run_times, self._logger.name)
|
|
f = self._eventloop.create_task(coro)
|
|
else:
|
|
f = self._eventloop.run_in_executor(None, run_job, job, job._jobstore_alias, run_times,
|
|
self._logger.name)
|
|
|
|
f.add_done_callback(callback)
|
|
self._pending_futures.add(f)
|