Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_nested_application_separate_scheduler(test_client):
app = web.Application()
aiojobs_setup(app)
app2 = web.Application()
aiojobs_setup(app2)
class MyView(web.View):
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()
app2.router.add_route("*", "/", MyView)
app.add_subapp("/sub/", app2)
client = await test_client(app)
resp = await client.get("/sub/")
assert resp.status == 200
def _init_subapp(pkg_name: str,
root_app: web.Application,
subapp: web.Application,
global_middlewares: Iterable[WebMiddleware]) -> None:
subapp.on_response_prepare.append(on_prepare)
async def _copy_public_interface_objs(subapp: web.Application):
# Allow subapp's access to the root app properties.
# These are the public APIs exposed to plugins as well.
for key, obj in public_interface_objs.items():
subapp[key] = obj
# We must copy the public interface prior to all user-defined startup signal handlers.
subapp.on_startup.insert(0, _copy_public_interface_objs)
prefix = subapp.get('prefix', pkg_name.split('.')[-1].replace('_', '-'))
aiojobs.aiohttp.setup(subapp, **root_app['scheduler_opts'])
root_app.add_subapp('/' + prefix, subapp)
root_app.middlewares.extend(global_middlewares)
# Add routes
apply_routes(app)
# before
app.middlewares.append(police_middleware)
# after
app.middlewares.append(errors_middleware)
sio, background_task = get_socket_io_route(sio, app)
app.on_startup.append(init_pg)
app.on_cleanup.append(close_pg)
app.on_cleanup.append(dispose_redis_pool)
sio.start_background_task(background_task)
setup_aiojobs(app)
if __name__ == '__main__':
web.run_app(app, host=os.getenv('HOST', '0.0.0.0'), port=os.getenv('PORT', '8080'))
- sets up URL routing
- initializes all main Virtool objects during ``on_startup``
"""
middlewares = [
virtool.http.errors.middleware,
virtool.http.proxy.middleware,
virtool.http.query.middleware
]
if skip_setup:
middlewares.append(virtool.app_auth.middleware)
app = web.Application(middlewares=middlewares)
aiojobs.aiohttp.setup(app)
app["version"] = force_version
app["db_name"] = db_name
app["db_host"] = db_host
app.on_startup.append(init_client_path)
if not skip_setup:
app.on_startup.append(init_setup)
else:
app.on_startup.append(init_version)
app.on_startup.append(init_http_client)
app.on_startup.append(init_routes)
if not ignore_settings:
app.on_startup.append(init_settings)
async def create_key_handler(request) -> web.StreamResponse:
return await broadcast_handler.create_key_handler(request)
@atomic
async def post_raffle_handler(request) -> web.StreamResponse:
return await broadcast_handler.post_raffle_handler(request)
loop.create_task(broadcast_handler.clean_rubbish())
tcp_core = asyncio.start_server(broadcast_handler.tcp_receiver_handle, '0.0.0.0', 8002, loop=loop)
loop.run_until_complete(tcp_core)
app = web.Application()
setup(app)
app.router.add_route('GET', '/check', check_handler)
app.router.add_route('GET', '/create_key', create_key_handler)
app.router.add_route('POST', '/post_raffle', post_raffle_handler)
app.on_shutdown.append(broadcast_handler.on_shutdown)
web.run_app(app, port=8001)