added name to build_task

added api_timeout and scrape_interval to scrape config
added requirements.txt
This commit is contained in:
Kirill Zhukov 2023-03-01 14:13:14 +01:00
parent 7543878abf
commit 97db2097d3
8 changed files with 23 additions and 8 deletions

View File

@ -60,7 +60,9 @@ class APIclient():
if task['started_at'] else None
finished_at = datetime.fromisoformat(task['finished_at']+TZ_OFFSET) \
if task['finished_at'] else None
name = task['ref']['url'].split('/')[-1].replace('.git', '')
params = {'id': task['id'],
'name': name,
'build_id': build_id,
'started_at': started_at,
'finished_at': finished_at,

View File

@ -35,12 +35,12 @@ class DB():
def insert_buildtask(self, build_task: BuildTaskDB):
sql = '''
INSERT INTO build_tasks(id, build_id, arch_id, started_at, finished_at, status_id)
VALUES (%s, %s, %s, %s, %s, %s);
INSERT INTO build_tasks(id, name, build_id, arch_id, started_at, finished_at, status_id)
VALUES (%s, %s, %s, %s, %s, %s, %s);
'''
cur = self.__conn.cursor()
cur.execute(sql, (build_task.id, build_task.build_id, build_task.arch_id,
cur.execute(sql, (build_task.id, build_task.name, build_task.build_id, build_task.arch_id,
build_task.started_at, build_task.finished_at, build_task.status_id))
self.__conn.commit()

View File

@ -86,5 +86,5 @@ def start(yml_path: str):
extractor.db.close_conn()
logging.info("Extraction was finished")
logging.info("Sleeping for %d seconds", config.scrape_inteval)
time.sleep(config.scrape_inteval)
logging.info("Sleeping for %d seconds", config.scrape_interval)
time.sleep(config.scrape_interval)

View File

@ -9,6 +9,7 @@ from .enums import ArchEnum
class BuildTask(BaseModel):
id: int
name: str
build_id: int
arch: str
started_at: Optional[datetime] = None
@ -22,6 +23,7 @@ class BuildTask(BaseModel):
if self.finished_at else None
params = {
'id': self.id,
'name': self.name,
'build_id': self.build_id,
'arch_id': ArchEnum[self.arch].value,
'started_at': started_at,

View File

@ -1,5 +1,5 @@
from typing import Optional
from pydantic import BaseModel
from pydantic import BaseModel # pylint: disable=no-name-in-module
class BuildTaskDB(BaseModel):
@ -7,6 +7,7 @@ class BuildTaskDB(BaseModel):
BuildTask as it received from/sent to database
"""
id: int
name: str
build_id: int
arch_id: int
started_at: Optional[float] = None

View File

@ -27,5 +27,5 @@ class ExtractorConfig(BaseModel):
api_timeout: int = Field(
description="max time in seconds to wait for API response",
default=API_DEFAULT)
scrape_inteval: int = Field(description='how often (in seconds) we will extract data from ALBS',
default=SCRAPE_INTERVAL_DEFAULT)
scrape_interval: int = Field(description='how often (in seconds) we will extract data from ALBS',
default=SCRAPE_INTERVAL_DEFAULT)

View File

@ -51,6 +51,7 @@ VALUES
DROP TABLE IF EXISTS build_tasks CASCADE;
CREATE TABLE build_tasks (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
build_id INTEGER REFERENCES builds(id) ON DELETE CASCADE,
arch_id INTEGER REFERENCES arch_enum(id) ON DELETE SET NULL,
status_id INTEGER REFERENCES build_task_status_enum(id) ON DELETE SET NULL,

View File

@ -0,0 +1,9 @@
certifi==2022.12.7
charset-normalizer==3.0.1
idna==3.4
psycopg2-binary==2.9.5
pydantic==1.10.5
PyYAML==6.0
requests==2.28.2
typing_extensions==4.5.0
urllib3==1.26.14