fix: align proof, treatment, metrics and site videos with PDF
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 5m44s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m22s
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 5m44s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m22s
This commit is contained in:
@@ -29,6 +29,7 @@ from zoneinfo import ZoneInfo
|
||||
from uuid import NAMESPACE_URL, UUID, uuid4, uuid5
|
||||
|
||||
from psycopg.types.json import Jsonb
|
||||
from PIL import Image
|
||||
|
||||
from .core.auth import audit
|
||||
from .core.db import connect
|
||||
@@ -68,7 +69,7 @@ def queue(c, order_id, items, only_missing=False):
|
||||
|
||||
|
||||
def claim(c):
|
||||
return c.execute('''SELECT p.*, o.snapshot, o.number, o.created_at AS ordered_at FROM dtf_local.print_files p
|
||||
return c.execute('''SELECT p.*, o.snapshot, o.number, o.parent_id, o.created_at AS ordered_at FROM dtf_local.print_files p
|
||||
JOIN dtf_local.orders o ON o.id=p.order_id
|
||||
WHERE p.status='pending' OR (p.status='rendering' AND p.claimed_at < now()-%s)
|
||||
ORDER BY CASE WHEN o.parent_id IS NOT NULL THEN 0 ELSE 1 END, p.created_at
|
||||
@@ -120,13 +121,32 @@ def render_one(storage):
|
||||
attempts=attempts+1,claim_token=%s WHERE id=%s''', (token, job['id']))
|
||||
job['claim_token'] = token
|
||||
item = job['snapshot']['items'][job['item_index']]
|
||||
source_ids = [UUID(u) for u in item['uploads']]
|
||||
# A format such as CDR needs a human to prepare the full-size final on
|
||||
# the parent. The child still generates its own 15 cm proof from that PNG.
|
||||
if job['parent_id']:
|
||||
source = c.execute('''SELECT u.id FROM dtf_local.order_files f
|
||||
JOIN dtf_local.uploads u ON u.id=f.upload_id
|
||||
WHERE f.order_id=%s AND f.item_index=%s AND f.kind='final' AND f.active
|
||||
AND u.purged_at IS NULL AND u.expires_at>now()
|
||||
ORDER BY f.created_at DESC LIMIT 1''',
|
||||
(job['parent_id'], item['proof_parent_item_index'])).fetchone()
|
||||
if source:
|
||||
source_ids = [source['id']]
|
||||
item = {**item, 'uploads': [str(source['id'])]}
|
||||
job['proof_fallback'] = True
|
||||
elif job['snapshot'].get('treatment'):
|
||||
job['wait_for_treatment'] = True
|
||||
uploads = c.execute('''SELECT id,name,size,object_key,scan_state,purged_at,expires_at,
|
||||
(expires_at<=now()) AS expired FROM dtf_local.uploads WHERE id=ANY(%s)''',
|
||||
([UUID(u) for u in item['uploads']],)).fetchall()
|
||||
(source_ids,)).fetchall()
|
||||
# Every generated file shares its order's artwork retention deadline.
|
||||
expiry = c.execute('SELECT min(created_at)+interval \'30 days\' AS e FROM dtf_local.uploads WHERE id=ANY(%s)',
|
||||
([UUID(u) for u in item['uploads']],)).fetchone()['e']
|
||||
(source_ids,)).fetchone()['e']
|
||||
by_id = {str(row['id']): row for row in uploads}
|
||||
if job.get('wait_for_treatment'):
|
||||
finish(job, 'manual', {'reason': 'Tratamento pago: prepare e aprove o PNG completo no pedido pai para gerar a prova.'})
|
||||
return True
|
||||
if any(row['size'] > LARGE_SOURCE_BYTES and not row['name'].lower().endswith(STREAMED) for row in uploads):
|
||||
finish(job, 'manual', {'reason': f'arquivo acima de {LARGE_SOURCE_BYTES // 1048576} MB que não é PNG nem PDF: '
|
||||
'monte a folha a partir do original'})
|
||||
@@ -249,6 +269,22 @@ def produce(storage, job, item, uploads):
|
||||
local = os.path.join(scratch, f'source-{index}')
|
||||
storage.fetch(uploads[upload_id]['object_key'], local)
|
||||
files[index] = (local, uploads[upload_id]['name'])
|
||||
if job.get('proof_fallback'):
|
||||
with Image.open(files[0][0]) as final:
|
||||
width_px, height_px = final.size
|
||||
width_cm = float(Decimal(width_px) * Decimal('2.54') / Decimal(300))
|
||||
height_cm = float(Decimal(height_px) * Decimal('2.54') / Decimal(300))
|
||||
original_height = float(item['production']['height_cm'])
|
||||
fraction = float(item.get('proof_y_fraction') or 0)
|
||||
source = {'kind': 'sheet', 'width_cm': width_cm, 'length_cm': height_cm,
|
||||
'copies': 1, 'rotation_degrees': 0, 'mirrored': False, 'measurement': 'file'}
|
||||
item = {**item, 'proof_y_fraction': min(1, fraction * original_height / height_cm),
|
||||
'production': {'version': 3, 'film_width_cm': width_cm,
|
||||
'height_cm': height_cm, 'sources': [source],
|
||||
'placements': [{'source_index': 0, 'copy_index': 0,
|
||||
'x_cm': 0, 'y_cm': 0, 'width_cm': width_cm,
|
||||
'length_cm': height_cm, 'rotation_degrees': 0,
|
||||
'mirrored': False}]}}
|
||||
proof_of = job['snapshot'].get('proof_of')
|
||||
# The child owns its final file; the class names its proof.
|
||||
prefix = (f'DTF-{job["number"]}-prova-{item.get("stroke_class") or "C3"}' if proof_of
|
||||
|
||||
Reference in New Issue
Block a user