From a17287a11872084226d3c70d99b49df4d2eef921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 12 Nov 2026 15:03:16 -0300 Subject: [PATCH] fix: a long film's print file gets a render limit per 15 m part Order #20 (23.6 m, 24 pieces) failed with "Falhou ao gerar": the whole film had one 15 min limit, and two parts at 300 DPI take longer on the server. The limit is now PRINT_RENDER_TIMEOUT_SECONDS (default 20 min) for each part, and each claim records its deadline, so the stale-claim check and the card's "Tempo limite" follow the same limit. A timeout, or a final failed attempt, is logged as an error so Sentry sees it. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/api/operator/board.py | 4 +- .../202611121500_print-deadline.sql | 3 + app/printjobs.py | 55 ++++++++++++++----- tests/test_proof_cut.py | 15 +++++ 4 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 app/migrations/202611121500_print-deadline.sql diff --git a/app/api/operator/board.py b/app/api/operator/board.py index 31a0adb..beb9c6b 100644 --- a/app/api/operator/board.py +++ b/app/api/operator/board.py @@ -173,8 +173,8 @@ def with_print_files(c, orders): ids = [o['id'] for o in orders] generated = c.execute('''SELECT p.order_id,p.item_index,p.status,p.upload_id,p.detail,p.claimed_at,p.finished_at, p.created_at, - (p.status='rendering' AND p.claimed_at= MAX_ATTEMPTS + if final: + logging.error('Print file generation failed: order #%s item %s: %s', + job['number'], job['item_index'] + 1, result) finish(job, 'failed' if final else 'pending', {'error': result, 'reason': 'A geração falhou. Gere de novo.' if final else ''}) return True diff --git a/tests/test_proof_cut.py b/tests/test_proof_cut.py index 29a628e..25d08c3 100644 --- a/tests/test_proof_cut.py +++ b/tests/test_proof_cut.py @@ -38,5 +38,20 @@ class ProofCutTests(unittest.TestCase): self.assertEqual(proof_cut(100, 15, None), [Decimal(0), Decimal(15)]) +class RenderLimitTests(unittest.TestCase): + """Order #20 (2026-11-12): a 23.6 m film ran past one 15 min limit.""" + + def test_the_limit_grows_with_the_parts(self): + from app.printjobs import RENDER_SECONDS, render_seconds + + def film(height): + return {'production': {'height_cm': height, 'placements': [ + {'y_cm': 0, 'length_cm': height, 'source_index': 0}]}} + self.assertEqual(render_seconds(film(800)), RENDER_SECONDS) + self.assertEqual(render_seconds(film(2359.2)), 2 * RENDER_SECONDS) + self.assertEqual(render_seconds(film(4600)), 4 * RENDER_SECONDS) + self.assertEqual(render_seconds({'mode': 'file'}), RENDER_SECONDS) + + if __name__ == '__main__': unittest.main()