Skip to content

Commit 46a197c

Browse files
committed
Use aiojobs for background tasks
1 parent 760ccab commit 46a197c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

aiocache/decorators.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import inspect
44
import logging
55

6+
import aiojobs
7+
68
from aiocache.base import SENTINEL
79
from aiocache.factory import Cache, caches
810
from aiocache.lock import RedLock
911

1012

1113
logger = logging.getLogger(__name__)
14+
loop = asyncio.get_event_loop()
15+
scheduler = loop.run_until_complete(aiojobs.create_scheduler(pending_limit=0, limit=None))
1216

1317

1418
class cached:
@@ -112,9 +116,7 @@ async def decorator(
112116
if aiocache_wait_for_write:
113117
await self.set_in_cache(key, result)
114118
else:
115-
# TODO: Use aiojobs to avoid warnings.
116-
asyncio.create_task(self.set_in_cache(key, result))
117-
119+
await scheduler.spawn(self.set_in_cache(key, result))
118120
return result
119121

120122
def get_cache_key(self, f, args, kwargs):
@@ -336,8 +338,7 @@ async def decorator(
336338
if aiocache_wait_for_write:
337339
await self.set_in_cache(result, f, args, kwargs)
338340
else:
339-
# TODO: Use aiojobs to avoid warnings.
340-
asyncio.create_task(self.set_in_cache(result, f, args, kwargs))
341+
await scheduler.spawn(self.set_in_cache(result, f, args, kwargs))
341342

342343
return result
343344

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-e .[dev,redis,memcached,msgpack]
2+
aiojobs==1.0.0
23
aiohttp==3.8.1
34
flake8==4.0.1
45
flake8-bandit==3.0.0

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'redis:python_version>="3.8"': ["aioredis>=1.3.0,<2.0"],
3939
"memcached": ["aiomcache>=0.5.2"],
4040
"msgpack": ["msgpack>=0.5.5"],
41+
"aiojobs": ["aiojobs>=1.0.0"],
4142
},
4243
include_package_data=True,
4344
)

0 commit comments

Comments
 (0)