Browse Source

Log exceptions better

master
Sean Johnson 2 years ago
parent
commit
f9036c5828
  1. 14
      resource/tools/backup-volumes.py

14
resource/tools/backup-volumes.py

@ -7,6 +7,7 @@ import os
import re
import shutil
import sys
import traceback
from datetime import datetime
from typing import Iterator, List, Optional, Sequence, Union
@ -40,13 +41,19 @@ def chunked_iter(items: Sequence, size: int) -> Iterator[List[List]]:
yield items[index : index + size]
def log_stdout(message, **context):
def log_stdout(message, exception: Optional[Exception] = None, **context):
message = {
"timestamp": timestamp_micros(),
"message": message,
"context": context,
}
if exception is not None:
message["exception"] = traceback.format_exception_only(
type(exception),
exception,
)
sys.stdout.write(json.dumps(message) + "\n")
@ -95,6 +102,11 @@ async def backup_all_volumes():
await asyncio.wait(tasks)
# Log exceptions for each task
for task in tasks:
if (err := task.exception()) is not None:
log_stdout(f"Backup task failed", exception=err, stack=task.get_stack())
async def backup_volume(vol_name: str, vol_data: str):
snapshot_name = await perform_volume_snapshot(vol_name, vol_data)

Loading…
Cancel
Save