Preserve active staging and read published originals on reprocessing

This commit is contained in:
Artyom
2026-11-06 10:59:33 +03:00
parent 2e428cf8e6
commit 9ba3076fa8
4 changed files with 43 additions and 11 deletions
@@ -300,6 +300,12 @@ class PostgresAttachmentRepository:
select(AttachmentRow.id, AttachmentRow.staging_key)
.where(
AttachmentRow.staging_key.is_not(None),
~select(JobRow.job_id)
.where(
JobRow.attachment_id == AttachmentRow.id,
JobRow.status.in_(["queued", "processing"]),
)
.exists(),
or_(
AttachmentRow.status == "ready",
(AttachmentRow.status == "failed")
@@ -566,12 +572,12 @@ class PostgresJobRepository:
await self._note(claimed, "claimed")
source = (
await self._session.execute(
select(AttachmentRow.staging_key, AttachmentRow.original_key).where(
AttachmentRow.id == job.attachment_id
)
select(
AttachmentRow.status, AttachmentRow.staging_key, AttachmentRow.original_key
).where(AttachmentRow.id == job.attachment_id)
)
).one()
staged = source.staging_key is not None
staged = source.status != "ready" and source.staging_key is not None
return Claim(
Lease(claimed, token), source.staging_key if staged else source.original_key, staged
)