s365b.core.runlog ================= .. py:module:: s365b.core.runlog .. autoapi-nested-parse:: Each job run's own log, kept in the database for download. Every log line that carries a ``run_id`` (bound on the logger, or bound to the running task with :func:`for_run`, which also covers the Graph client and other module-level loggers) is copied into that run's log. Lines are collected in memory and written in batches by :func:`collecting`, which the worker runs for as long as it works. Lines go to stdout as before. A run keeps at most :data:`MAX_LINES` lines; the rest are counted and the count is noted at the end. Lines whose write failed (the database was unreachable) are kept and written with the next batch, up to :data:`MAX_PENDING` lines in all; past that the oldest are dropped and a warning goes to stdout. Writing the log never fails a run. Housekeeping deletes run logs older than its ``run_log_days`` setting. Attributes ---------- .. autoapisummary:: s365b.core.runlog.MAX_LINES s365b.core.runlog.MAX_PENDING s365b.core.runlog.FLUSH_SECONDS s365b.core.runlog.HEAD Functions --------- .. autoapisummary:: s365b.core.runlog.capture s365b.core.runlog.for_run s365b.core.runlog.flush s365b.core.runlog.finish s365b.core.runlog.collecting s365b.core.runlog.render Module Contents --------------- .. py:data:: MAX_LINES :value: 20000 .. py:data:: MAX_PENDING :value: 100000 .. py:data:: FLUSH_SECONDS :value: 2.0 .. py:data:: HEAD :value: ('timestamp', 'level', 'event', 'run_id') .. py:function:: capture(logger: Any, method: str, event_dict: collections.abc.MutableMapping[str, Any]) -> collections.abc.MutableMapping[str, Any] Structlog processor: copy lines that name a run into its log. :param logger: Unused. :param method: Unused. :param event_dict: The line's fields; returned unchanged. :returns: ``event_dict``. .. py:function:: for_run(run_id: int) -> None Tag every line the current task (and tasks it starts) logs with a run. :param run_id: The run. .. py:function:: flush(db: s365b.db.session.Database) -> None :async: Write the queued lines now. :param db: Database. .. py:function:: finish(db: s365b.db.session.Database) -> None :async: Write the current run's log now that it is done. Never raises. The run is the one bound to this task by :func:`for_run`, if any. :param db: Database. .. py:function:: collecting(db: s365b.db.session.Database) -> collections.abc.AsyncIterator[None] :async: Collect run logs while the block runs, writing them every few seconds. :param db: Database. :Yields: Nothing. .. py:function:: render(entry: dict[str, Any]) -> str One stored line as text: time, level, event, then the other fields. :param entry: The line's fields. :returns: The line, without a newline.