Skip to content

_update_jobs()

Class: JobsAustriaCacheSynchronizer
File: jobs_austria_cache_synchronizer.py · line 245

Bulk UPDATE of jobs using executemany. Payload column mapping: employment_type → position inserted_updated → publication_date (DD.MM.YYYY → DATE) salary → original_salary education → education

Signature

Parameters df
Returns not annotated
Async No
Visibility Private

Implementation

def _update_jobs(self, df: pd.DataFrame):
    """
    Bulk UPDATE of jobs using executemany.
    Payload column mapping:
      employment_type  → position
      inserted_updated → publication_date  (DD.MM.YYYY → DATE)
      salary           → original_salary
      education        → education
    """
    records = []
    for row in df.itertuples():
        records.append({
            "job_id":           int(row.jobs_id),
            "company_id":       int(row.company_id) if pd.notna(getattr(row, 'company_id', None)) else None,
            "location_id":      int(row.location_id) if pd.notna(getattr(row, 'location_id', None)) else None,
            "position":         self._str_or_none(getattr(row, 'employment_type', None)),
            "publication_date": self._parse_date(getattr(row, 'inserted_updated', None)),
            "contract_type":    self._str_or_none(getattr(row, 'contract_type', None)),
            "detailed_location":self._str_or_none(getattr(row, 'locations', None)),
            "original_salary":  self._str_or_none(getattr(row, 'salary', None)),
            "education":        self._str_or_none(getattr(row, 'education', None)),
            "portal":           self._extract_portal(getattr(row, 'url', None)),
        })

    if not records:
        return

    with self.engine.begin() as conn:
        conn.execute(
            text(
                "UPDATE jobs SET "
                "  company_id        = COALESCE(:company_id,        company_id), "
                "  location_id       = COALESCE(:location_id,       location_id), "
                "  position          = COALESCE(:position,          position), "
                "  publication_date  = COALESCE(:publication_date,  publication_date), "
                "  contract_type     = COALESCE(:contract_type,     contract_type), "
                "  detailed_location = COALESCE(:detailed_location, detailed_location), "
                "  original_salary   = COALESCE(:original_salary,   original_salary), "
                "  education         = COALESCE(:education,         education), "
                "  portal            = COALESCE(:portal,            portal) "
                "WHERE id = :job_id"
            ),
            records,
        )