Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 969 Lines • ▼ Show 20 Lines | ) -> List[OriginVisitStats]: | ||||
OriginVisitStats.select_columns(), | OriginVisitStats.select_columns(), | ||||
) | ) | ||||
rows = psycopg2.extras.execute_values( | rows = psycopg2.extras.execute_values( | ||||
cur=cur, sql=query, argslist=primary_keys, fetch=True | cur=cur, sql=query, argslist=primary_keys, fetch=True | ||||
) | ) | ||||
return [OriginVisitStats(**row) for row in rows] | return [OriginVisitStats(**row) for row in rows] | ||||
@db_transaction() | @db_transaction() | ||||
def visit_scheduler_queue_position_get( | |||||
self, db=None, cur=None, | |||||
) -> Dict[str, datetime.datetime]: | |||||
cur.execute("SELECT visit_type, position FROM visit_scheduler_queue_position") | |||||
return {row["visit_type"]: row["position"] for row in cur} | |||||
@db_transaction() | |||||
def visit_scheduler_queue_position_set( | |||||
self, visit_type: str, position: datetime.datetime, db=None, cur=None, | |||||
) -> None: | |||||
query = """ | |||||
INSERT INTO visit_scheduler_queue_position(visit_type, position) | |||||
VALUES(%s, %s) | |||||
ON CONFLICT(visit_type) DO UPDATE SET position=EXCLUDED.position | |||||
""" | |||||
cur.execute(query, (visit_type, position)) | |||||
@db_transaction() | |||||
def update_metrics( | def update_metrics( | ||||
self, | self, | ||||
lister_id: Optional[UUID] = None, | lister_id: Optional[UUID] = None, | ||||
timestamp: Optional[datetime.datetime] = None, | timestamp: Optional[datetime.datetime] = None, | ||||
db=None, | db=None, | ||||
cur=None, | cur=None, | ||||
) -> List[SchedulerMetrics]: | ) -> List[SchedulerMetrics]: | ||||
"""Update the performance metrics of this scheduler instance. | """Update the performance metrics of this scheduler instance. | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |