|
|
|
|
@ -2,7 +2,6 @@ from datetime import date, datetime
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import select
|
|
|
|
|
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
|
|
from gimme_job.constants import CONSECUTIVE_FAILURES_THRESHOLD
|
|
|
|
|
@ -10,7 +9,6 @@ from gimme_job.models.db import (
|
|
|
|
|
JobPosting,
|
|
|
|
|
NotificationLog,
|
|
|
|
|
SiteConfig,
|
|
|
|
|
SiteManifestVersion,
|
|
|
|
|
SiteRun,
|
|
|
|
|
Summary,
|
|
|
|
|
)
|
|
|
|
|
@ -71,10 +69,16 @@ class JobPostingRepo:
|
|
|
|
|
return len(candidates), new_count
|
|
|
|
|
|
|
|
|
|
def get_today_new(self, session: Session, run_date: date, since=None) -> list[JobPosting]:
|
|
|
|
|
q = select(JobPosting).where(JobPosting.run_date == run_date, JobPosting.is_new == True)
|
|
|
|
|
q = select(JobPosting).where(
|
|
|
|
|
JobPosting.run_date == run_date, JobPosting.is_new.is_(True)
|
|
|
|
|
)
|
|
|
|
|
if since is not None:
|
|
|
|
|
q = q.where(JobPosting.first_seen_at >= since)
|
|
|
|
|
return list(session.execute(q.order_by(JobPosting.site_id, JobPosting.first_seen_at)).scalars().all())
|
|
|
|
|
return list(
|
|
|
|
|
session.execute(
|
|
|
|
|
q.order_by(JobPosting.site_id, JobPosting.first_seen_at)
|
|
|
|
|
).scalars().all()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_by_site(self, session: Session, site_id: str) -> list[JobPosting]:
|
|
|
|
|
return list(
|
|
|
|
|
@ -156,7 +160,7 @@ class SiteConfigRepo:
|
|
|
|
|
def get_all_enabled(self, session: Session) -> list[SiteConfig]:
|
|
|
|
|
return list(
|
|
|
|
|
session.execute(
|
|
|
|
|
select(SiteConfig).where(SiteConfig.enabled == True)
|
|
|
|
|
select(SiteConfig).where(SiteConfig.enabled.is_(True))
|
|
|
|
|
).scalars().all()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -184,6 +188,7 @@ class SiteConfigRepo:
|
|
|
|
|
def record_success(self, session: Session, site_id: str) -> None:
|
|
|
|
|
config = self._get_or_create(session, site_id)
|
|
|
|
|
config.consecutive_failures = 0
|
|
|
|
|
config.repair_needed = False
|
|
|
|
|
config.last_success_at = datetime.utcnow()
|
|
|
|
|
session.flush()
|
|
|
|
|
|
|
|
|
|
|