def _sync()

in src/wagtail_localize_smartling/sync.py [0:0]


def _sync(job: "Job") -> None:
    """
    If the job has been synced to Smartling before, get its status and take the
    appropriate action if anything has changed.
    """
    if job.status == JobStatus.UNSYNCED:
        raise ValueError("call _initial_sync before calling _sync")

    logger.info("Syncing job %s", job)

    initial_status = job.status
    logger.info("Initial status: %s", initial_status)

    try:
        job_data = client.get_job_details(job=job)
    except JobNotFound:
        logger.warning("Job not found in Smartling, marking as deleted")
        updated_status = JobStatus.DELETED
    else:
        updated_status = job_data["jobStatus"]
        job.description = job_data["description"]
        job.reference_number = job_data["referenceNumber"] or ""
        job.due_date = job_data["dueDate"]

    job.status = updated_status
    job.last_synced_at = timezone.now()
    job.save()

    if updated_status == initial_status:
        logger.info("No change in status, no further action required")
        return

    logger.info("Updated status: %s", updated_status)

    if initial_status in PENDING_STATUSES:
        if updated_status in PENDING_STATUSES:
            logger.info("Job still pending, no further action required")
        elif updated_status in TRANSLATED_STATUSES:
            _download_and_apply_translations(job)
            job.translations_imported_at = job.last_synced_at
            job.save(update_fields=["translations_imported_at"])
        elif updated_status in UNTRANSLATED_STATUSES:
            logger.warning("Job is finalised but not translated")
    else:
        logger.info("Job already finalised, no further action required")