示例#1
0
    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):
            if run_coroutine_job is not None:
                coro = run_coroutine_job(job, job._jobstore_alias, run_times,
                                         self._logger.name)
                f = self._eventloop.create_task(coro)
            else:
                raise Exception(
                    'Executing coroutine based jobs is not supported with Trollius'
                )
        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)
示例#2
0
    def _do_submit_job(self, job, run_times):
        def callback(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):
            f = run_coroutine_job(job, job._jobstore_alias, run_times, self._logger.name)
        else:
            f = self.executor.submit(run_job, job, job._jobstore_alias, run_times,
                                     self._logger.name)

        f = convert_yielded(f)
        f.add_done_callback(callback)
示例#3
0
 def test_coro_partial(self):
     assert iscoroutinefunction_partial(partial(self.a_coro, 1))
示例#4
0
 def test_non_coro(self):
     assert not iscoroutinefunction_partial(self.not_a_coro)