forked from erp-dev/erp
feat: backfill external order image upgrade to beat schedule by 1 hour
This commit is contained in:
@@ -31,6 +31,7 @@ from api_v1.mdy_plate_order_staging_tiia_upload import (
|
||||
build_default_tiia_rate_limiter,
|
||||
upload_mdy_plate_order_staging_plate_images_to_tencent_tiia,
|
||||
)
|
||||
from api_v1.external_product_image_backfill import run_external_product_image_backfill
|
||||
from printing import models as printing_models
|
||||
|
||||
|
||||
@@ -424,6 +425,37 @@ def _upload_product_image(product, image_payload: dict):
|
||||
product.save(update_fields=['image', 'updated_at'])
|
||||
|
||||
|
||||
@shared_task(bind=True)
|
||||
def backfill_external_product_images(
|
||||
self,
|
||||
merchant_id: int | None = None,
|
||||
product_id: int | None = None,
|
||||
limit: int = 500,
|
||||
dry_run: bool = False,
|
||||
):
|
||||
"""
|
||||
为来自外部印染订单的产品补图。
|
||||
|
||||
仅处理:
|
||||
- printing_order.external_order_id 非空
|
||||
- product.image 为空
|
||||
"""
|
||||
payload = run_external_product_image_backfill(
|
||||
fetch_image=_fetch_external_product_image,
|
||||
upload_image=_upload_product_image,
|
||||
merchant_id=merchant_id,
|
||||
product_id=product_id,
|
||||
limit=max(1, int(limit or 500)),
|
||||
dry_run=bool(dry_run),
|
||||
on_success=lambda message: logger.info(message),
|
||||
on_error=lambda message: logger.error(message),
|
||||
on_info=lambda message: logger.info(message),
|
||||
)
|
||||
payload["task_id"] = self.request.id
|
||||
logger.info("外部印染订单产品补图完成: %s", payload)
|
||||
return payload
|
||||
|
||||
|
||||
def _record_printing_external_sync_failure(*, run_date, record: dict, error: str):
|
||||
external_record_id = _extract_positive_int(record.get('ID'), field_name='ID', allow_blank=False)
|
||||
obj, _created = api_models.PrintingExternalSyncFailure.objects.get_or_create(
|
||||
|
||||
Reference in New Issue
Block a user