1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Change the creation of the refreshing task, since call_later can't be used with coroutines

This commit is contained in:
phxntxm 2017-06-16 03:47:49 -05:00
parent 6ab89c1ba5
commit ce22d44a86

View file

@ -29,12 +29,16 @@ class Cache:
self.loop = loop
self.values = [] # The values returned from the database
self.refreshed_time = None
self.loop.create_task(self.check_refresh())
self.loop.create_task(self.refresh_task())
async def refresh(self):
self.values = await self.db.actual_load(self.table)
self.refreshed_time = datetime.now()
async def refresh_task(self):
await self.check_refresh()
await asyncio.sleep(60)
async def check_refresh(self):
if self.refreshed_time is None:
await self.refresh()
@ -43,8 +47,6 @@ class Cache:
if difference.total_seconds() > 300:
await self.refresh()
self.loop.call_later(60, self.check_refresh())
def get(self, key=None, table_filter=None, pluck=None):
"""This simulates the database call, to make it easier to get the data"""
if key is None and table_filter is None: