-
-
Notifications
You must be signed in to change notification settings - Fork 663
/
http.py
31 lines (22 loc) · 885 Bytes
/
http.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Copyright (C) 2017-2024 Bryant Moscon - bmoscon@gmail.com
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import logging
import aiohttp
from cryptofeed.backends.backend import BackendQueue
LOG = logging.getLogger('feedhandler')
class HTTPCallback(BackendQueue):
def __init__(self, addr: str, **kwargs):
self.addr = addr
self.session = None
self.running = True
async def http_write(self, data, headers=None):
if not self.session or self.session.closed:
self.session = aiohttp.ClientSession()
async with self.session.post(self.addr, data=data, headers=headers) as resp:
if resp.status >= 400:
error = await resp.text()
LOG.error("POST to %s failed: %d - %s", self.addr, resp.status, error)
resp.raise_for_status()