|
@@ -5,6 +5,8 @@ import os
|
|
|
import aiopg
|
|
|
import jinja2
|
|
|
import psycopg2.extras
|
|
|
+import asyncio_redis
|
|
|
+from asyncio_redis.protocol import HiRedisProtocol
|
|
|
import aiohttp.web
|
|
|
import aiohttp_jinja2
|
|
|
import api_hour
|
|
@@ -25,6 +27,7 @@ class Container(api_hour.Container):
|
|
|
# routes
|
|
|
self.servers['http'].router.add_route('GET', '/json', endpoints.world.json)
|
|
|
self.servers['http'].router.add_route('GET', '/db', endpoints.world.db)
|
|
|
+ self.servers['http'].router.add_route('GET', '/db_redis', endpoints.world.db_redis)
|
|
|
self.servers['http'].router.add_route('GET', '/queries', endpoints.world.queries)
|
|
|
self.servers['http'].router.add_route('GET', '/fortunes', endpoints.world.fortunes)
|
|
|
self.servers['http'].router.add_route('GET', '/updates', endpoints.world.updates)
|
|
@@ -50,8 +53,14 @@ class Container(api_hour.Container):
|
|
|
password=self.config['engines']['pg']['password'],
|
|
|
cursor_factory=psycopg2.extras.RealDictCursor,
|
|
|
minsize=int(self.config['engines']['pg']['minsize']),
|
|
|
- maxsize=int(self.config['engines']['pg']['maxsize'])))
|
|
|
+ maxsize=int(self.config['engines']['pg']['maxsize']),
|
|
|
+ loop=self.loop))
|
|
|
yield from asyncio.wait([self.engines['pg']], return_when=asyncio.ALL_COMPLETED)
|
|
|
+ self.engines['redis'] = yield from asyncio_redis.Pool.create(host=self.config['engines']['redis']['host'],
|
|
|
+ port=self.config['engines']['redis']['port'],
|
|
|
+ poolsize=self.config['engines']['redis']['poolsize'],
|
|
|
+ loop=self.loop,
|
|
|
+ protocol_class=HiRedisProtocol)
|
|
|
|
|
|
LOG.info('All engines ready !')
|
|
|
|
|
@@ -65,5 +74,8 @@ class Container(api_hour.Container):
|
|
|
yield from self.engines['pg'].result().wait_closed()
|
|
|
else:
|
|
|
yield from self.engines['pg'].cancel()
|
|
|
+ if 'redis' in self.engines:
|
|
|
+ self.engines['redis'].close()
|
|
|
+ yield from asyncio.sleep(1) # wait redis close connection
|
|
|
LOG.info('All engines stopped !')
|
|
|
yield from super().stop()
|