Added Ruff linting
This commit is contained in:
1 parent
c39513e4ff
commit
8a3630aca4
7 files changed
+59
-24
No files matched your search
@@ -1,11 +1,13 @@
|
||||
from contextlib import asynccontextmanager
|
||||
import aiomysql
|
||||
import asyncio
|
||||
from secret_manager import return_credentials
|
||||
import os
|
||||
from simple_logger_handler import setup_logger
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import aiomysql
|
||||
import pymysql.err
|
||||
|
||||
from secret_manager import return_credentials
|
||||
from simple_logger_handler import setup_logger
|
||||
|
||||
db_username = return_credentials("/etc/secrets/db_username")
|
||||
db_password = return_credentials("/etc/secrets/db_password")
|
||||
db_host = os.getenv("BACKEND_PN_DB_HOST","localhost")
|
||||
|
||||
@@ -41,7 +41,7 @@ async def remove_inactive_push_token(uuid :str, db_manager):
|
||||
async with db_manager.acquire() as conn:
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute("UPDATE device_tokens SET status='expired' WHERE token_id=%s",
|
||||
(uuid,))
|
||||
(uuid,))
|
||||
success = cur.rowcount > 0
|
||||
logger.debug(f"[DB] Token expiration for uuid={uuid} success={success}")
|
||||
return success
|
||||
+4
-2
@@ -1,7 +1,9 @@
|
||||
from prometheus_client import Counter, Gauge, start_http_server
|
||||
from simple_logger_handler import setup_logger
|
||||
import asyncio
|
||||
|
||||
from prometheus_client import Counter, Gauge, start_http_server
|
||||
|
||||
from simple_logger_handler import setup_logger
|
||||
|
||||
logger = setup_logger(__name__)
|
||||
|
||||
MSG_PUBLISHED = Counter(
|
||||
|
||||
+12
-10
@@ -1,16 +1,18 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
|
||||
import aio_pika
|
||||
from aio_pika.exceptions import AMQPException
|
||||
from secret_manager import return_credentials, cleanup_secret_files
|
||||
from secret_manager.fernet_encryption import decrypt_token
|
||||
from device_token_repository import database_lookup_by_user_id, remove_inactive_push_token, database_lookup_by_uuid
|
||||
import os
|
||||
from simple_logger_handler import setup_logger
|
||||
import json
|
||||
from db import db_manager
|
||||
from send_notification import send_notification
|
||||
import signal
|
||||
|
||||
import metrics
|
||||
from db import db_manager
|
||||
from device_token_repository import database_lookup_by_user_id, database_lookup_by_uuid, remove_inactive_push_token
|
||||
from secret_manager import cleanup_secret_files, return_credentials
|
||||
from secret_manager.fernet_encryption import decrypt_token
|
||||
from send_notification import send_notification
|
||||
from simple_logger_handler import setup_logger
|
||||
|
||||
logger = setup_logger(__name__)
|
||||
|
||||
@@ -70,7 +72,7 @@ class RabbitMQConsumer:
|
||||
logger.debug(f"[RabbitMQ] DLQ queue '{self.dlq_queue_name}' declared.")
|
||||
|
||||
metrics.start_metrics_server(port=9000)
|
||||
logger.debug(f"[Metrics] Prometheus metrics server started on port 9000.")
|
||||
logger.debug("[Metrics] Prometheus metrics server started on port 9000.")
|
||||
|
||||
self._metric_tasks = [
|
||||
asyncio.create_task(metrics.update_queue_gauge(self.channel, self.queue_name)),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import aiohttp
|
||||
import aiodns
|
||||
import asyncio
|
||||
|
||||
import aiohttp
|
||||
|
||||
from simple_logger_handler import setup_logger
|
||||
|
||||
API_ENDPOINT="https://exp.host/--/api/v2/push/send"
|
||||
@@ -15,15 +16,15 @@ retryable_exceptions = (
|
||||
)
|
||||
|
||||
|
||||
async def send_notification(message: dict, push_tokens, max_retries: int = 5, timeout: int = 5):
|
||||
async def send_notification(message: dict, push_tokens, max_retries: int = 5):
|
||||
logger.debug(f"[Notification] Sending to {len(push_tokens)} push tokens")
|
||||
results = {}
|
||||
for uuid, token in push_tokens.items():
|
||||
logger.debug(f"[Notification] Preparing to send to uuid={uuid}")
|
||||
results[uuid] = await _send_to_token(token, uuid, message, max_retries, timeout)
|
||||
results[uuid] = await _send_to_token(token, uuid, message, max_retries)
|
||||
return results
|
||||
|
||||
async def _send_to_token(token: str, uuid:str , message: dict, max_retries: int, timeout: int):
|
||||
async def _send_to_token(token: str, uuid:str , message: dict, max_retries: int):
|
||||
payload = create_payload(token, message)
|
||||
logger.debug(f"[Notification] Payload for uuid={uuid}: {payload}")
|
||||
|
||||
@@ -36,8 +37,7 @@ async def _send_to_token(token: str, uuid:str , message: dict, max_retries: int,
|
||||
async with session.post(
|
||||
url=API_ENDPOINT,
|
||||
json=payload,
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=timeout
|
||||
headers={"Content-Type": "application/json"}
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
data = await response.json()
|
||||
|
||||
Reference in new issue
Block a user