71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""Shared constants for monitors and the consumer bot.
|
|
|
|
Holds Mongo connection settings, bot tokens, retry and timeout tuning,
|
|
client fingerprint identifiers, webhook routing maps, product status values,
|
|
and the expected error tuple used for known-failure handling.
|
|
"""
|
|
|
|
import asyncio
|
|
from enum import Enum
|
|
from json import JSONDecodeError
|
|
|
|
import aiohttp
|
|
import requests
|
|
from aioweb import AiowebError
|
|
from curl_cffi.requests.errors import RequestsError
|
|
from pymongo.errors import PyMongoError
|
|
|
|
MONGO_DATABASE_NAME = "tpv_woot"
|
|
MONGO_URL = (
|
|
"mongodb://tpv:n3%23QI07GnbZCbvGJ@zelda.disqualifier.me:27017/?authSource=tpv_woot"
|
|
)
|
|
LOGGING_LEVEL = "INFO"
|
|
LOGGERS = [
|
|
"discord",
|
|
"pymongo",
|
|
"aiohttp",
|
|
]
|
|
|
|
RETRY_LIMIT = 5
|
|
RETRY_WAIT = 3
|
|
CYCLE_DELAY = 0.30
|
|
MIN_BACKOFF_DELAY = 0.1
|
|
MAX_BACKOFF_DELAY = 2.0
|
|
FAILURE_DELAY = 3
|
|
|
|
TIMEOUT_SECONDS = 30
|
|
CYCLE_TIMEOUT_SECONDS = 600
|
|
# curl_cffi's AsyncSession defaults to 10 handles and blocks on an untimed
|
|
# pool.get() past that, so a monitor fanning out wider silently serialises with
|
|
# no timeout covering the wait. Handles are allocated lazily (the pool holds
|
|
# None placeholders until popped), so a generous ceiling costs a low-concurrency
|
|
# monitor nothing. Monitors fanning out past this pass max_clients explicitly.
|
|
MAX_CURL_HANDLES = 64
|
|
# Budget for closing a session. curl_cffi's close awaits the multi handle with
|
|
# no timeout of its own, so a wedged transfer would otherwise park whatever is
|
|
# closing the session, including an `async with` exit.
|
|
SESSION_CLOSE_TIMEOUT_SECONDS = 10
|
|
CLIENT_IDENTIFIERS = ["chrome", "chrome_android", "safari", "safari_ios"]
|
|
CLIENT_TIMEOUT = aiohttp.ClientTimeout(
|
|
total=TIMEOUT_SECONDS, sock_connect=30, sock_read=30
|
|
)
|
|
EXPECTED_TASK_ERRORS = (
|
|
RequestsError,
|
|
aiohttp.ClientError,
|
|
asyncio.TimeoutError,
|
|
requests.Timeout,
|
|
requests.HTTPError,
|
|
PyMongoError,
|
|
JSONDecodeError,
|
|
AiowebError,
|
|
)
|
|
|
|
|
|
class ProductStatus(str, Enum):
|
|
"""Lifecycle status for a monitored product document."""
|
|
|
|
PENDING = "pending"
|
|
SENT = "sent"
|
|
SKIPPED = "skipped"
|
|
FAILED = "failed"
|