in src/wagtail_localize_smartling/sync.py [0:0]
def sync_job(job_id: int) -> None:
"""
Sync the state of a Job instance with the corresponding job in Smartling.
This uses select_for_update() to lock the Job row for the duration of the
method. These locks are only released when the _transaction_ ends, not
savepoints. To ensure we don't accidentally create long-lasting locks on the
the Job rows, we pass durable=True to the atomic decorator. That means that
this atomic() block is definitely the outermost one and the transaction will
be committed or rolled back at the end of this function.
NB - this takes an ID, rather than a job instance, so that it's always
operating on current data rather than pickled state. That means it's safe
to be called after arbitrary time from the background task queue, if one
is in use.
"""
from .models import Job
try:
job = Job.objects.select_for_update().get(pk=job_id)
except Job.DoesNotExist as e:
raise JobNotFound(f"Job with ID {job_id} not found") from e
try:
if job.status == JobStatus.UNSYNCED:
_initial_sync(job)
else:
_sync(job)
except Exception as e:
raise SyncJobException(f"Exception syncing job {job}") from e