feat: add job progress, retry and rotating logs

This commit is contained in:
strsv committed 2026-11-06 07:52:16 +03:00
1 parent 626650e44a
commit c441d770e2
16 files changed
+297 -72

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
"""Tests for the rotating structured server log."""
import json
import os
import sys
import tempfile
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "tools"))
sys.path.insert(0, os.path.join(ROOT, "web"))
import server
class ServerLogTests(unittest.TestCase):
def test_writes_json_lines_without_request_bodies(self):
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "server.log")
handler = server.setup_logging(path)
try:
server.log_event("job_finish", name="translate", exit_code=0, cancelled=False)
handler.flush()
finally:
handler.close()
server.LOG.removeHandler(handler)
with open(path, encoding="utf-8") as fh:
records = [json.loads(line) for line in fh if line.strip()]
self.assertEqual(len(records), 1)
record = records[0]
self.assertEqual(record["event"], "job_finish")
self.assertEqual(record["name"], "translate")
self.assertEqual(record["exit_code"], 0)
self.assertIn("ts", record)
self.assertNotIn("notes", record)
self.assertNotIn("body", record)
def test_setup_is_idempotent_and_rotates(self):
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "server.log")
first = server.setup_logging(path)
second = server.setup_logging(path)
try:
self.assertIs(first, second)
self.assertEqual(first.maxBytes, 1024 * 1024)
self.assertEqual(first.backupCount, 3)
finally:
second.close()
server.LOG.removeHandler(second)
if __name__ == "__main__":
unittest.main()