Keep enrichment locks alive during long batches
This commit is contained in:
@@ -2505,7 +2505,7 @@ def mobilede_enrich_images_batch_task(
|
||||
|
||||
redis_client = _get_redis()
|
||||
owner_token = str(getattr(self.request, "id", None) or uuid.uuid4().hex)
|
||||
lock_ttl = max(300, int(float(os.getenv("MOBILEDE_ENRICH_LOCK_TTL_SECONDS", "3600"))))
|
||||
lock_ttl = max(300, int(float(os.getenv("MOBILEDE_ENRICH_LOCK_TTL_SECONDS", "300"))))
|
||||
if not _acquire_lock(redis_client, MOBILEDE_ENRICH_IMAGES_LOCK_KEY, owner_token, lock_ttl):
|
||||
return {
|
||||
"status": "locked",
|
||||
@@ -2529,6 +2529,23 @@ def mobilede_enrich_images_batch_task(
|
||||
for batch_start in range(0, len(candidates), effective_batch_size):
|
||||
batch = candidates[batch_start:batch_start + effective_batch_size]
|
||||
for _car_id, origin_id, origin_url, image_count in batch:
|
||||
if not _refresh_lock_if_owner(
|
||||
redis_client,
|
||||
MOBILEDE_ENRICH_IMAGES_LOCK_KEY,
|
||||
owner_token,
|
||||
lock_ttl,
|
||||
):
|
||||
logger.warning(
|
||||
"mobile.de image enrich lock ownership lost; stopping before origin_id=%s",
|
||||
origin_id,
|
||||
)
|
||||
return {
|
||||
"status": "lock_lost",
|
||||
"candidates": len(candidates),
|
||||
"enriched": enriched,
|
||||
"failed": failed,
|
||||
"skipped": skipped,
|
||||
}
|
||||
listing_id = _mobilede_extract_listing_id(origin_url) or str(origin_id).rsplit(":", 1)[-1]
|
||||
if not listing_id:
|
||||
skipped += 1
|
||||
|
||||
Reference in New Issue
Block a user