How to use the aiojobs.aiohttp.get_scheduler_from_app function in aiojobs

To help you get started, we’ve selected a few aiojobs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiojobs / tests / test_aiohttp.py View on Github external
async def get(self):
            assert get_scheduler_from_request(self.request) !=\
                get_scheduler_from_app(app)
            assert get_scheduler_from_request(self.request) ==\
                get_scheduler_from_app(app2)
            return web.Response()
github aio-libs / aiojobs / tests / test_aiohttp.py View on Github external
async def test_atomic_from_view(test_client):
    app = web.Application()

    class MyView(web.View):
        @atomic
        async def get(self):
            return web.Response()

    app.router.add_route("*", "/", MyView)
    aiojobs_setup(app)

    client = await test_client(app)
    resp = await client.get('/')
    assert resp.status == 200

    scheduler = get_scheduler_from_app(app)

    assert scheduler.active_count == 0
    assert scheduler.pending_count == 0
github aio-libs / aiojobs / tests / test_aiohttp.py View on Github external
async def get(self):
            assert get_scheduler_from_request(self.request) ==\
                get_scheduler_from_app(app)
            return web.Response()
github virtool / virtool / virtool / app.py View on Github external
try:
        await app["dispatcher"].close()
    except KeyError:
        pass

    try:
        app["executor"].shutdown(wait=True)
    except KeyError:
        pass

    try:
        app["process_executor"].shutdown(wait=True)
    except KeyError:
        pass

    scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)
    await scheduler.close()
github virtool / virtool / virtool / app.py View on Github external
async def init_refresh(app):
    scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)
    await scheduler.spawn(virtool.db.references.refresh_remotes(app))
    await scheduler.spawn(virtool.db.hmm.refresh(app))
    await scheduler.spawn(virtool.db.software.refresh(app))
github virtool / virtool / virtool / app.py View on Github external
"""
    if app["setup"] is not None:
        return

    if app["settings"]["no_job_manager"]:
        return logger.info("Running without job manager")

    capture_exception = None

    if "sentry" in app:
        capture_exception = app["sentry"].captureException

    app["jobs"] = virtool.jobs.manager.IntegratedManager(app, capture_exception)

    scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)

    await scheduler.spawn(app["jobs"].run())
github virtool / virtool / virtool / app.py View on Github external
"""
    A function called when the app is shutting down.

    :param app: the app object
    :type app: :class:`aiohttp.web.Application`

    """
    logger.debug("Shutting down")

    await app["client"].close()
    await app["dispatcher"].close()

    app["executor"].shutdown(wait=True)
    app["process_executor"].shutdown(wait=True)

    scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)
    await scheduler.close()
github virtool / virtool / virtool / app.py View on Github external
:type app: :class:`aiohttp.web.Application`

    """
    files_path = os.path.join(app["settings"].get("data_path"), "files")

    if os.path.isdir(files_path):
        app["file_manager"] = virtool.files.Manager(
            app.loop,
            app["executor"],
            app["db"],
            files_path,
            app["settings"].get("watch_path"),
            clean_interval=20
        )

        scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)

        await scheduler.spawn(app["file_manager"].run())
    else:
        logger.warning("Did not initialize file manager. Path does not exist: {}".format(files_path))
        app["file_manager"] = None
github lablup / backend.ai-manager / src / ai / backend / gateway / events.py View on Github external
async def dispatch_subscribers(self, event_name: str, agent_id: AgentId,
                                   args: Tuple[Any, ...] = tuple()) -> None:
        log_fmt = 'DISPATCH_SUBSCRIBERS(ev:{}, ag:{})'
        log_args = (event_name, agent_id)
        if self.root_app['config']['debug']['log-events']:
            log.debug(log_fmt, *log_args)
        scheduler = get_scheduler_from_app(self.root_app)
        for subscriber in self.subscribers[event_name]:
            cb = subscriber.callback
            try:
                if asyncio.iscoroutine(cb):
                    await scheduler.spawn(cb)
                elif asyncio.iscoroutinefunction(cb):
                    await scheduler.spawn(cb(subscriber.context, agent_id, event_name, *args))
                else:
                    cb = functools.partial(cb, subscriber.context, agent_id, event_name, *args)
                    self.loop.call_soon(cb)
            except asyncio.CancelledError:
                raise
            except Exception:
                log.exception(log_fmt + ': unexpected-error', *log_args)