FSM storage closing now is async

This commit is contained in:
Alex Root Junior 2017-10-18 22:32:21 +03:00
parent 84c8548ceb
commit 17871155ee
4 changed files with 4 additions and 4 deletions

View file

@ -13,7 +13,7 @@ class MemoryStorage(BaseStorage):
async def wait_closed(self): async def wait_closed(self):
pass pass
def close(self): async def close(self):
self.data.clear() self.data.clear()
def __init__(self): def __init__(self):

View file

@ -43,7 +43,7 @@ class RedisStorage(BaseStorage):
self._redis: aioredis.RedisConnection = None self._redis: aioredis.RedisConnection = None
self._connection_lock = asyncio.Lock(loop=self._loop) self._connection_lock = asyncio.Lock(loop=self._loop)
def close(self): async def close(self):
if self._redis and not self._redis.closed: if self._redis and not self._redis.closed:
self._redis.close() self._redis.close()
del self._redis del self._redis

View file

@ -6,7 +6,7 @@ class BaseStorage:
In states-storage you can save current user state and data for all steps In states-storage you can save current user state and data for all steps
""" """
def close(self): async def close(self):
""" """
Need override this method and use when application is shutdowns. Need override this method and use when application is shutdowns.
You can save data or etc. You can save data or etc.

View file

@ -143,7 +143,7 @@ async def on_shutdown(app):
await bot.delete_webhook() await bot.delete_webhook()
# Close Redis connection. # Close Redis connection.
dp.storage.close() await dp.storage.close()
await dp.storage.wait_closed() await dp.storage.wait_closed()