Changeset - 74b4acd3dde0
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 18:47:35
drewp@bigasterisk.com
collector client retries a bit. not sure we want this.
3 files changed with 41 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/collector/collector_client_asyncio.py
Show inline comments
 
import logging
 
import tenacity
 
from light9 import networking
 
from light9.collector.collector_client import toCollectorJson
 
from light9.effect.settings import DeviceSettings
 
import aiohttp
 

	
 
class Sender:
 

	
 
log = logging.getLogger('coll_client')
 

	
 

	
 
class _Sender:
 

	
 
    def __init__(self):
 
        pass#self.http_session = aiohttp.ClientSession()
 
        self.reconnect()
 

	
 
    def reconnect(self):
 
        self.http_session = aiohttp.ClientSession()
 

	
 
    async def send(self, client: str, session: str, settings: DeviceSettings):
 
        msg = toCollectorJson(client, session, settings).encode('utf8')
 

	
 
        async with aiohttp.ClientSession() as ses: # i want to use the one from __init__!
 
            async with ses.put(
 
                networking.collector.path('attrs'), data=msg, timeout=1) as resp:
 
        @tenacity.retry(
 
            retry=tenacity.retry_if_exception_type(aiohttp.ServerTimeoutError),
 
            reraise=True, 
 
            stop=tenacity.stop_after_attempt(3),
 
            )
 
        async def put():
 

	
 
            async with self.http_session.put(networking.collector.path('attrs'), data=msg, timeout=.2) as resp:
 
                if resp.status != 202:
 
                    body = await resp.text()
 
                    self.reconnect()
 
                    raise ValueError(f'collector returned {resp.status}: {body}')
 

	
 
_sender = Sender()
 
        await put()
 
        attempts = put.retry.statistics['attempt_number']
 
        if attempts!=1:
 
            log.warning(f"{attempts=}")
 

	
 

	
 
_sender = _Sender()
 

	
 

	
 
async def sendToCollector(client: str, session: str, settings: DeviceSettings, useZmq=False):
 
    await _sender.send(client, session, settings)
pdm.lock
Show inline comments
 
@@ -826,12 +826,18 @@ summary = "Statistical profiling for Pyt
 
[[package]]
 
name = "stdlib-list"
 
version = "0.8.0"
 
summary = "A list of Python Standard Libraries (2.6-7, 3.2-9)."
 

	
 
[[package]]
 
name = "tenacity"
 
version = "8.2.2"
 
requires_python = ">=3.6"
 
summary = "Retry code until it succeeds"
 

	
 
[[package]]
 
name = "tomli"
 
version = "2.0.1"
 
requires_python = ">=3.7"
 
summary = "A lil' TOML parser"
 

	
 
[[package]]
 
@@ -1023,13 +1029,13 @@ summary = "Interfaces for Python"
 
dependencies = [
 
    "setuptools",
 
]
 

	
 
[metadata]
 
lock_version = "4.1"
 
content_hash = "sha256:b143dcaeecae81f7c7c117ef8680f17f1e7ba3b43102cf94d5dd000299db60bc"
 
content_hash = "sha256:dc1401c032c754cf047170f72e28807ba5f94185bb51f54d2b038dbacf44ac64"
 

	
 
[metadata.files]
 
"aiohttp 3.8.4" = [
 
    {url = "https://files.pythonhosted.org/packages/03/e7/84b65e341b1f45753fea51158d8a9522e57a5ae804acbc6dc34edf07cea0/aiohttp-3.8.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:bca5f24726e2919de94f047739d0a4fc01372801a3672708260546aa2601bf57"},
 
    {url = "https://files.pythonhosted.org/packages/04/03/3ce412b191aba5961b4ada3ee7a93498623e218fb4d50ac6d357da61dc26/aiohttp-3.8.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:8189c56eb0ddbb95bfadb8f60ea1b22fcfa659396ea36f6adcc521213cd7b44d"},
 
    {url = "https://files.pythonhosted.org/packages/05/ee/77b3dc08f41a1bce842e30134233c58b3bbe8c0fa7be121295aa2fad885d/aiohttp-3.8.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:17b79c2963db82086229012cff93ea55196ed31f6493bb1ccd2c62f1724324e4"},
 
@@ -2212,12 +2218,16 @@ content_hash = "sha256:b143dcaeecae81f7c
 
    {url = "https://files.pythonhosted.org/packages/5b/00/8a05eb398e72f3aa5ec22a027bdffa51fd4f74296c7cb82f7b434d622296/statprof-0.1.2.tar.gz", hash = "sha256:adb8654edd5183e91e1538ee9112314f8129a52796bfa32cfa34b2f0e73295b4"},
 
]
 
"stdlib-list 0.8.0" = [
 
    {url = "https://files.pythonhosted.org/packages/7a/b1/52f59dcf31ead2f0ceff8976288449608d912972b911f55dff712cef5719/stdlib_list-0.8.0-py3-none-any.whl", hash = "sha256:2ae0712a55b68f3fbbc9e58d6fa1b646a062188f49745b495f94d3310a9fdd3e"},
 
    {url = "https://files.pythonhosted.org/packages/bb/01/237cea071fd305f162ebbe1db18a59b56b0b5fdff19533c9a1beea0bdee7/stdlib-list-0.8.0.tar.gz", hash = "sha256:a1e503719720d71e2ed70ed809b385c60cd3fb555ba7ec046b96360d30b16d9f"},
 
]
 
"tenacity 8.2.2" = [
 
    {url = "https://files.pythonhosted.org/packages/d3/f0/6ccd8854f4421ce1f227caf3421d9be2979aa046939268c9300030c0d250/tenacity-8.2.2.tar.gz", hash = "sha256:43af037822bd0029025877f3b2d97cc4d7bb0c2991000a3d59d71517c5c969e0"},
 
    {url = "https://files.pythonhosted.org/packages/e7/b0/c23bd61e1b32c9b96fbca996c87784e196a812da8d621d8d04851f6c8181/tenacity-8.2.2-py3-none-any.whl", hash = "sha256:2f277afb21b851637e8f52e6a613ff08734c347dc19ade928e519d7d2d8569b0"},
 
]
 
"tomli 2.0.1" = [
 
    {url = "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
 
    {url = "https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
 
]
 
"toposort 1.10" = [
 
    {url = "https://files.pythonhosted.org/packages/69/19/8e955d90985ecbd3b9adb2a759753a6840da2dff3c569d412b2c9217678b/toposort-1.10.tar.gz", hash = "sha256:bfbb479c53d0a696ea7402601f4e693c97b0367837c8898bc6471adfca37a6bd"},
pyproject.toml
Show inline comments
 
@@ -34,12 +34,13 @@ dependencies = [
 
    "udmx-pyusb>=2.0.0",
 
    "uvicorn[standard]>=0.17.6",
 
    "watchdog>=2.1.7",
 
    "webcolors>=1.11.1",
 
    "scipy>=1.9.3",
 
    "braillegraph>=0.6",
 
    "tenacity>=8.2.2",
 
]
 
requires-python = ">=3.10"
 

	
 
[project.urls]
 
Homepage = ""
 

	
0 comments (0 inline, 0 general)