feat: 삭제된 콘텐츠의 대기·예약 업로드 정리와 실행 가드 추가

This commit is contained in:
skkim committed 2026-10-16 11:29:42 +09:00
1 parent cf6949acf7
commit 3854aef320
3 files changed
+69 -6

No files matched your search

+21 -6
View File
@@ -144,26 +144,29 @@ async def _increment_retry_count(upload_id: int) -> int:
return 0
async def _resolve_source_url(session, upload: SocialUpload) -> Optional[str]:
"""업로드가 가리키는 콘텐츠 종류의 영상 URL. 병합 스키마라 채워진 FK 가 곧 종류다."""
async def _resolve_source(session, upload: SocialUpload) -> tuple[Optional[str], bool]:
"""업로드가 가리키는 콘텐츠의 (영상 URL, 삭제 여부). 병합 스키마라 채워진 FK 가 곧 종류다.
콘텐츠 행이 없으면 (None, False) — 삭제가 아니라 "찾을 수 없음"으로 구분한다.
"""
if upload.p2v_video_id is not None:
row = (
await session.execute(
select(PosterAliveTask).where(PosterAliveTask.id == upload.p2v_video_id)
)
).scalar_one_or_none()
return row.video_url if row else None
return (row.video_url, bool(row.is_deleted)) if row else (None, False)
if upload.content_id is not None:
row = (
await session.execute(
select(SsulContent).where(SsulContent.id == upload.content_id)
)
).scalar_one_or_none()
return row.video_url if row else None
return (row.video_url, bool(row.is_deleted)) if row else (None, False)
row = (
await session.execute(select(Video).where(Video.id == upload.video_id))
).scalar_one_or_none()
return row.result_movie_url if row else None
return (row.result_movie_url, bool(row.is_deleted)) if row else (None, False)
async def process_social_upload(upload_id: int) -> None:
@@ -192,7 +195,19 @@ async def process_social_upload(upload_id: int) -> None:
return
# 2. 대상 영상 조회. video_id / content_id / p2v_video_id 중 정확히 하나만 채워져 있다(CHECK).
source_url = await _resolve_source_url(session, upload)
source_url, target_deleted = await _resolve_source(session, upload)
# 삭제된 콘텐츠는 올리지 않는다 — 소프트 삭제라 예약·재시도 업로드가 남아 있을 수 있다.
if target_deleted:
logger.warning(
f"[SOCIAL_UPLOAD] 삭제된 콘텐츠라 업로드하지 않음 - upload_id: {upload_id}"
)
await _update_upload_status(
upload_id=upload_id,
status=UploadStatus.CANCELLED,
error_message="삭제된 콘텐츠라 업로드하지 않았습니다.",
)
return
if not source_url:
logger.error(