The API ran as one uvicorn process, so a slow 150 MB PDF check at checkout held every other request; WEB_CONCURRENCY now comes from API_WORKERS (default 2, 1 restores one process) and the api /tmp grows to 512 MiB for two checks at once. The worker delivered one outbox job per second; it now drains up to 50 per pass before its periodic tasks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
906 B
Python
28 lines
906 B
Python
"""The outbox worker drains a backlog instead of one job per second (item 9).
|
|
|
|
Run from the repository root: python3 -m unittest tests.test_worker_drain -v.
|
|
The worker imports psycopg and boto3, so a host without the API image's
|
|
dependencies cannot import it; CI runs this in the api container.
|
|
"""
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from app import worker
|
|
|
|
|
|
class WorkerDrainTest(unittest.TestCase):
|
|
def test_drain_stops_when_the_queue_is_empty(self):
|
|
with mock.patch.object(worker, 'tick',
|
|
side_effect=[True, True, True, False]) as tick:
|
|
worker.drain()
|
|
self.assertEqual(tick.call_count, 4)
|
|
|
|
def test_drain_stops_at_the_limit(self):
|
|
with mock.patch.object(worker, 'tick', return_value=True) as tick:
|
|
worker.drain()
|
|
self.assertEqual(tick.call_count, 50)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|