Skip to content

run_cycle()

Class: JobsAustriaCacheSynchronizer
File: jobs_austria_cache_synchronizer.py · line 294

One cycle: handles both queues. 1. New unlinked rows (fk_job_id IS NULL) → synchronize_fk_id → synchronize_company_id 2. Linked but unenriched rows → synchronize_company_id directly Returns False when both queues are empty.

Signature

Parameters none
Returns bool
Async No
Visibility Public

Implementation

def run_cycle(self) -> bool:
    """
    One cycle: handles both queues.
    1. New unlinked rows (fk_job_id IS NULL)  → synchronize_fk_id → synchronize_company_id
    2. Linked but unenriched rows              → synchronize_company_id directly
    Returns False when both queues are empty.
    """
    has_work = False

    # Queue 1: rows not yet linked to a job
    df_unlinked = self._fetch_fk_pending_batch()
    if not df_unlinked.empty:
        has_work = True
        df_enriched = self.synchronize_fk_id(df_unlinked)
        self.synchronize_company_id(df_enriched)
        logs.info(f"Queue 1: processed {len(df_unlinked)} unlinked rows.")

    # Queue 2: rows already linked but job payload not yet extracted
    df_unenriched = self._fetch_payload_pending_batch()
    if not df_unenriched.empty:
        has_work = True
        self.synchronize_company_id(df_unenriched)
        logs.info(f"Queue 2: processed {len(df_unenriched)} unenriched rows.")

    if not has_work:
        logs.info("Both queues empty. Stopping.")

    return has_work