summaryrefslogtreecommitdiff
path: root/apscheduler/executors/twisted.py
blob: a0b1570849ff8844b41d422aa60f4b5bf32b529f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import absolute_import

from apscheduler.executors.base import BaseExecutor, run_job


class TwistedExecutor(BaseExecutor):
    """
    Runs jobs in the reactor's thread pool.

    Plugin alias: ``twisted``
    """

    def start(self, scheduler, alias):
        super(TwistedExecutor, self).start(scheduler, alias)
        self._reactor = scheduler._reactor

    def _do_submit_job(self, job, run_times):
        def callback(success, result):
            if success:
                self._run_job_success(job.id, result)
            else:
                self._run_job_error(job.id, result.type, result.value, result.tb)

        self._reactor.getThreadPool().callInThreadWithCallback(callback, run_job, job, job._jobstore_alias, run_times,
                                                               self._logger.name)