Render crop and optimized variants next to the thumbnail
The worker decodes the original once (JPEG draft down to the optimized box, EXIF orientation applied in place, alpha composed on white) and encodes three variants: the 256 px thumbnail, a centred 128x128 JPEG crop that may upscale and a WebP fitted into 1280x1280 without upscaling, quality 80, method 4. No EXIF, ICC or XMP is written. The byte limit is checked before decoding. ready is set by the transaction that stores all three rows, so a partial set is never published. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
045d631c12
commit
431b82fd43
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
from uuid import UUID
|
||||
|
||||
@@ -21,13 +22,15 @@ from messenger.attachments.application.ports import Faults, ObjectStorage, Varia
|
||||
from messenger.attachments.domain.jobs import Job, Outcome, RetryPolicy
|
||||
from messenger.attachments.entrypoints.schemas import JobMessage
|
||||
from messenger.attachments.infrastructure.faults import EnvironmentFaults
|
||||
from messenger.attachments.infrastructure.images import PillowVariantRenderer
|
||||
from messenger.attachments.infrastructure.images import PillowVariantRenderer, RenderLimits
|
||||
from messenger.attachments.infrastructure.postgres import PostgresAttachmentsUnitOfWork
|
||||
from messenger.shared.application.errors import Unavailable
|
||||
from messenger.shared.infrastructure.clock import MonotonicUtcClock
|
||||
from messenger.shared.infrastructure.ids import Uuid7Generator
|
||||
from messenger.shared.infrastructure.postgres import Database
|
||||
|
||||
IDLE_SECONDS = 0.1
|
||||
LIMITS = RenderLimits(10_485_760, 40_000_000)
|
||||
FAST = RetryPolicy(max_attempts=5, base_seconds=0.001, cap_seconds=0.001)
|
||||
|
||||
|
||||
@@ -62,7 +65,7 @@ class InlinePipeline:
|
||||
self.policy = policy
|
||||
self.lease = lease
|
||||
self.publisher = CapturingPublisher()
|
||||
self.renderer: VariantRenderer = PillowVariantRenderer(40_000_000, 2)
|
||||
self.renderer: VariantRenderer = PillowVariantRenderer(LIMITS, 2)
|
||||
self.faults: Faults = EnvironmentFaults("", NullLogger())
|
||||
|
||||
def uow(self) -> PostgresAttachmentsUnitOfWork:
|
||||
@@ -88,12 +91,16 @@ class InlinePipeline:
|
||||
)
|
||||
return await handler(ProcessJob(job))
|
||||
|
||||
async def drain(self, rounds: int = 20) -> list[Outcome]:
|
||||
async def drain(self, rounds: int = 20, idle: int = 3) -> list[Outcome]:
|
||||
outcomes: list[Outcome] = []
|
||||
quiet = 0
|
||||
for _ in range(rounds):
|
||||
jobs = await self.publish()
|
||||
if not jobs:
|
||||
quiet = 0 if jobs else quiet + 1
|
||||
if quiet == idle:
|
||||
return outcomes
|
||||
if not jobs:
|
||||
await asyncio.sleep(IDLE_SECONDS)
|
||||
outcomes.extend([await self.process(job) for job in jobs])
|
||||
return outcomes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user