Merge branch 'feature/RES-809' into 'master'

RES-809: update kn_utils

See merge request knecon/research/pyinfra!101
This commit is contained in:
Jonathan Kössler 2024-10-23 18:01:25 +02:00
commit 46dc1fdce4
7 changed files with 1067 additions and 970 deletions

View File

@ -26,6 +26,7 @@ repos:
rev: v3.0.0a5 rev: v3.0.0a5
hooks: hooks:
- id: pylint - id: pylint
language: system
args: args:
- --disable=C0111,R0903 - --disable=C0111,R0903
- --max-line-length=120 - --max-line-length=120

1965
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,6 @@ from aiormq.exceptions import AMQPConnectionError
from dynaconf import Dynaconf from dynaconf import Dynaconf
from fastapi import FastAPI from fastapi import FastAPI
from kn_utils.logging import logger from kn_utils.logging import logger
from tenacity import (
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from pyinfra.config.loader import get_pyinfra_validators, validate_settings from pyinfra.config.loader import get_pyinfra_validators, validate_settings
from pyinfra.queue.async_manager import AsyncQueueManager, RabbitMQConfig from pyinfra.queue.async_manager import AsyncQueueManager, RabbitMQConfig

View File

@ -20,13 +20,7 @@ from aio_pika.exceptions import (
) )
from aiormq.exceptions import AMQPConnectionError from aiormq.exceptions import AMQPConnectionError
from kn_utils.logging import logger from kn_utils.logging import logger
from tenacity import ( from kn_utils.retry import retry
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
wait_exponential_jitter,
)
@dataclass @dataclass
@ -82,9 +76,8 @@ class AsyncQueueManager:
self.message_count: int = 0 self.message_count: int = 0
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=AMQPConnectionError,
retry=retry_if_exception_type(AMQPConnectionError),
reraise=True, reraise=True,
) )
async def connect(self) -> None: async def connect(self) -> None:
@ -121,9 +114,8 @@ class AsyncQueueManager:
return True return True
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=(AMQPConnectionError, ChannelInvalidStateError),
retry=retry_if_exception_type((AMQPConnectionError, ChannelInvalidStateError)),
reraise=True, reraise=True,
) )
async def setup_exchanges(self) -> None: async def setup_exchanges(self) -> None:
@ -138,9 +130,8 @@ class AsyncQueueManager:
) )
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=(AMQPConnectionError, ChannelInvalidStateError),
retry=retry_if_exception_type((AMQPConnectionError, ChannelInvalidStateError)),
reraise=True, reraise=True,
) )
async def setup_tenant_queue(self) -> None: async def setup_tenant_queue(self) -> None:
@ -263,9 +254,8 @@ class AsyncQueueManager:
logger.info(f"Published result to queue {tenant_id}.") logger.info(f"Published result to queue {tenant_id}.")
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential_jitter(initial=1, max=10), exceptions=(aiohttp.ClientResponseError, aiohttp.ClientConnectorError),
retry=retry_if_exception_type((aiohttp.ClientResponseError, aiohttp.ClientConnectorError)),
reraise=True, reraise=True,
) )
async def fetch_active_tenants(self) -> Set[str]: async def fetch_active_tenants(self) -> Set[str]:
@ -282,9 +272,8 @@ class AsyncQueueManager:
return set() return set()
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=(AMQPConnectionError, ChannelInvalidStateError),
retry=retry_if_exception_type((AMQPConnectionError, ChannelInvalidStateError)),
reraise=True, reraise=True,
) )
async def initialize_tenant_queues(self) -> None: async def initialize_tenant_queues(self) -> None:

View File

@ -10,9 +10,8 @@ import pika
import pika.exceptions import pika.exceptions
from dynaconf import Dynaconf from dynaconf import Dynaconf
from kn_utils.logging import logger from kn_utils.logging import logger
from kn_utils.retry import retry
from pika.adapters.blocking_connection import BlockingChannel, BlockingConnection from pika.adapters.blocking_connection import BlockingChannel, BlockingConnection
from retry import retry
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
from pyinfra.config.loader import validate_settings from pyinfra.config.loader import validate_settings
from pyinfra.config.validators import queue_manager_validators from pyinfra.config.validators import queue_manager_validators
@ -59,9 +58,8 @@ class QueueManager:
return pika.ConnectionParameters(**pika_connection_params) return pika.ConnectionParameters(**pika_connection_params)
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=(pika.exceptions.AMQPConnectionError, pika.exceptions.ChannelClosedByBroker),
retry=retry_if_exception_type((pika.exceptions.AMQPConnectionError, pika.exceptions.ChannelClosedByBroker)),
reraise=True, reraise=True,
) )
def establish_connection(self): def establish_connection(self):
@ -95,9 +93,8 @@ class QueueManager:
return False return False
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=4, max=60), exceptions=pika.exceptions.AMQPConnectionError,
retry=retry_if_exception_type(pika.exceptions.AMQPConnectionError),
reraise=True, reraise=True,
) )
def start_consuming(self, message_processor: Callable): def start_consuming(self, message_processor: Callable):

View File

@ -10,21 +10,15 @@ import uvicorn
from dynaconf import Dynaconf from dynaconf import Dynaconf
from fastapi import FastAPI from fastapi import FastAPI
from kn_utils.logging import logger from kn_utils.logging import logger
from tenacity import ( from kn_utils.retry import retry
retry,
retry_if_exception_type,
stop_after_attempt,
wait_exponential,
)
from pyinfra.config.loader import validate_settings from pyinfra.config.loader import validate_settings
from pyinfra.config.validators import webserver_validators from pyinfra.config.validators import webserver_validators
@retry( @retry(
stop=stop_after_attempt(5), tries=5,
wait=wait_exponential(multiplier=1, min=2, max=30), exceptions=Exception,
retry=retry_if_exception_type((Exception,)), # You might want to be more specific here
reraise=True, reraise=True,
) )
def create_webserver_thread_from_settings(app: FastAPI, settings: Dynaconf) -> threading.Thread: def create_webserver_thread_from_settings(app: FastAPI, settings: Dynaconf) -> threading.Thread:

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "pyinfra" name = "pyinfra"
version = "3.2.11" version = "3.3.0"
description = "" description = ""
authors = ["Team Research <research@knecon.com>"] authors = ["Team Research <research@knecon.com>"]
license = "All rights reseverd" license = "All rights reseverd"
@ -19,7 +19,7 @@ azure-storage-blob = "^12.13"
funcy = "^2" funcy = "^2"
pycryptodome = "^3.19" pycryptodome = "^3.19"
# research shared packages # research shared packages
kn-utils = { version = "^0.2.7", source = "gitlab-research" } kn-utils = { version = "^0.3.0", source = "gitlab-research" }
fastapi = "^0.109.0" fastapi = "^0.109.0"
uvicorn = "^0.26.0" uvicorn = "^0.26.0"
# [tool.poetry.group.telemetry.dependencies] # [tool.poetry.group.telemetry.dependencies]
@ -39,13 +39,12 @@ azure-monitor-opentelemetry = "^1.6.0"
protobuf = ">=3.20 <5.0.0" protobuf = ">=3.20 <5.0.0"
aio-pika = "^9.4.2" aio-pika = "^9.4.2"
aiohttp = "^3.9.5" aiohttp = "^3.9.5"
tenacity = "^8.5.0"
opentelemetry-instrumentation-aio-pika = "0.46b0" opentelemetry-instrumentation-aio-pika = "0.46b0"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
pytest = "^7" pytest = "^7"
ipykernel = "^6.26.0" ipykernel = "^6.26.0"
black = "^23.10" black = "^24.10"
pylint = "^3" pylint = "^3"
coverage = "^7.3" coverage = "^7.3"
requests = "^2.31" requests = "^2.31"