2023-03-16 17:57:31 +00:00
|
|
|
from datetime import datetime, timedelta
|
2023-02-27 19:51:53 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-02-28 17:28:48 +00:00
|
|
|
from pydantic import HttpUrl, Field, BaseModel # pylint: disable=no-name-in-module
|
2023-02-27 19:51:53 +00:00
|
|
|
|
|
|
|
from .db_config import DbConfig
|
|
|
|
|
|
|
|
# DEFAULTS
|
|
|
|
ALBS_URL_DEFAULT = 'https://build.almalinux.org'
|
|
|
|
LOG_FILE_DEFAULT = '/tmp/extractor.log'
|
2023-02-28 17:28:48 +00:00
|
|
|
API_DEFAULT = 30
|
|
|
|
SCRAPE_INTERVAL_DEFAULT = 3600
|
2023-03-06 18:21:56 +00:00
|
|
|
START_FROM_DEFAULT = 5808
|
2023-03-16 17:57:31 +00:00
|
|
|
OLDEST_TO_UPDATE_DEFAULT = datetime.now().astimezone() - timedelta(days=3)
|
2023-02-27 19:51:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ExtractorConfig(BaseModel):
|
|
|
|
"""
|
|
|
|
config model for Extractor service
|
|
|
|
"""
|
|
|
|
log_file: Path = Field(description='logfile path',
|
|
|
|
default=LOG_FILE_DEFAULT)
|
|
|
|
albs_url: HttpUrl = Field(description='ALBS root URL',
|
|
|
|
default=ALBS_URL_DEFAULT)
|
|
|
|
oldest_build_age: datetime = \
|
2023-03-06 18:21:56 +00:00
|
|
|
Field(description='oldest build age to store')
|
2023-02-27 19:51:53 +00:00
|
|
|
jwt: str = Field(description='ALBS JWT token')
|
|
|
|
db_config: DbConfig = Field(description="database configuration")
|
2023-02-28 17:28:48 +00:00
|
|
|
api_timeout: int = Field(
|
|
|
|
description="max time in seconds to wait for API response",
|
|
|
|
default=API_DEFAULT)
|
2023-03-01 13:13:14 +00:00
|
|
|
scrape_interval: int = Field(description='how often (in seconds) we will extract data from ALBS',
|
|
|
|
default=SCRAPE_INTERVAL_DEFAULT)
|
2023-03-06 18:21:56 +00:00
|
|
|
start_from: int = Field(description='build id to start populating empty db with',
|
|
|
|
default=START_FROM_DEFAULT)
|
2023-03-16 17:57:31 +00:00
|
|
|
oldest_to_update: datetime = \
|
|
|
|
Field(description='oldest unfinished object (build/task/step...) that we will try to update',
|
|
|
|
default=OLDEST_TO_UPDATE_DEFAULT)
|