Skip to content

Commit 330b212

Browse files
committed
modified httputils.py to incorporate an aggregrate
1 parent 1c7e4ae commit 330b212

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

app/utils/httputils.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33

44
from aiohttp import ClientSession
55

6-
# Singleton aiohttp.ClientSession instance.
7-
CLIENT_SESSION: ClientSession
86

7+
class Session:
8+
# Singleton aiohttp.ClientSession instance.
9+
CLIENT_SESSION: ClientSession
10+
LOGGER = logging.getLogger(__name__)
911

10-
LOGGER = logging.getLogger(__name__)
12+
async def setup_client_session(self):
13+
"""Set up the application-global aiohttp.ClientSession instance.
1114
15+
aiohttp recommends that only one ClientSession exist for the lifetime of an application.
16+
See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request
1217
13-
async def setup_client_session():
14-
"""Set up the application-global aiohttp.ClientSession instance.
18+
"""
19+
global CLIENT_SESSION # pylint: disable=global-statement
20+
self.LOGGER.info("Setting up global aiohttp.ClientSession.")
21+
CLIENT_SESSION = ClientSession()
1522

16-
aiohttp recommends that only one ClientSession exist for the lifetime of an application.
17-
See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request
18-
19-
"""
20-
global CLIENT_SESSION # pylint: disable=global-statement
21-
LOGGER.info("Setting up global aiohttp.ClientSession.")
22-
CLIENT_SESSION = ClientSession()
23-
24-
25-
async def teardown_client_session():
26-
"""Close the application-global aiohttp.ClientSession.
27-
"""
28-
global CLIENT_SESSION # pylint: disable=global-statement
29-
LOGGER.info("Closing global aiohttp.ClientSession.")
30-
await CLIENT_SESSION.close()
23+
async def teardown_client_session(self):
24+
"""Close the application-global aiohttp.ClientSession.
25+
"""
26+
global CLIENT_SESSION # pylint: disable=global-statement
27+
self.LOGGER.info("Closing global aiohttp.ClientSession.")
28+
await CLIENT_SESSION.close()

0 commit comments

Comments
 (0)