Skip to content

Commit

Permalink
Use aiojobs for background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
citramon committed May 18, 2022
1 parent 760ccab commit 3821a57
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions aiocache/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import inspect
import logging

import aiojobs

from aiocache.base import SENTINEL
from aiocache.factory import Cache, caches
from aiocache.lock import RedLock


logger = logging.getLogger(__name__)
scheduler = asyncio.run(aiojobs.create_scheduler(pending_limit=0, limit=None))


class cached:
Expand Down Expand Up @@ -112,9 +115,7 @@ async def decorator(
if aiocache_wait_for_write:
await self.set_in_cache(key, result)
else:
# TODO: Use aiojobs to avoid warnings.
asyncio.create_task(self.set_in_cache(key, result))

await scheduler.spawn(self.set_in_cache(key, result))
return result

def get_cache_key(self, f, args, kwargs):
Expand Down Expand Up @@ -336,8 +337,7 @@ async def decorator(
if aiocache_wait_for_write:
await self.set_in_cache(result, f, args, kwargs)
else:
# TODO: Use aiojobs to avoid warnings.
asyncio.create_task(self.set_in_cache(result, f, args, kwargs))
await scheduler.spawn(self.set_in_cache(result, f, args, kwargs))

return result

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-e .[dev,redis,memcached,msgpack]
aiojobs==1.0.0
aiohttp==3.8.1
flake8==4.0.1
flake8-bandit==3.0.0
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'redis:python_version>="3.8"': ["aioredis>=1.3.0,<2.0"],
"memcached": ["aiomcache>=0.5.2"],
"msgpack": ["msgpack>=0.5.5"],
"aiojobs": ["aiojobs>=1.0.0"],
},
include_package_data=True,
)

0 comments on commit 3821a57

Please sign in to comment.