Improve logging (use logfmt and avoid logging noops every hour)

This commit is contained in:
MMK21Hub 2026-04-14 20:38:15 +01:00
parent 79e065bd2a
commit 40ee264f08
No known key found for this signature in database
GPG key ID: 7E0FBF3E19DB8E10
2 changed files with 14 additions and 11 deletions

View file

@ -57,13 +57,16 @@ async def main(_app: Starlette):
from nephthys.tasks.close_stale import close_stale_tickets
from datetime import datetime
scheduler.add_job(
close_stale_tickets,
"interval",
hours=1,
max_instances=1,
next_run_time=datetime.now(),
)
if env.stale_ticket_days:
scheduler.add_job(
close_stale_tickets,
"interval",
hours=1,
max_instances=1,
next_run_time=datetime.now(),
)
else:
logging.debug("Stale ticket closing has not been configured")
scheduler.start()
delete_msg_task = asyncio.create_task(process_queue())

View file

@ -91,10 +91,10 @@ async def close_stale_tickets():
stale_ticket_days = env.stale_ticket_days
if not stale_ticket_days:
logging.info("Stale ticket auto-close is disabled (STALE_TICKET_DAYS not set)")
logging.warning("Skipping ticket auto-close (STALE_TICKET_DAYS not set)")
return
logging.info(f"Closing stale tickets (threshold: {stale_ticket_days} days)...")
logging.info(f"Closing stale tickets, threshold_days={stale_ticket_days}")
await send_heartbeat(
f"Closing stale tickets (threshold: {stale_ticket_days} days)..."
)
@ -111,7 +111,7 @@ async def close_stale_tickets():
for i in range(0, len(tickets), batch_size):
batch = tickets[i : i + batch_size]
logging.info(
f"Processing batch {i // batch_size + 1}/{(len(tickets) + batch_size - 1) // batch_size}"
f"Processing stale tickets batch={i // batch_size + 1} batches={(len(tickets) + batch_size - 1) // batch_size}"
)
for ticket in batch:
@ -140,7 +140,7 @@ async def close_stale_tickets():
await send_heartbeat(f"Closed {stale} stale tickets.")
logging.info(f"Closed {stale} stale tickets.")
logging.info(f"Closed stale tickets. count={stale}")
except Exception as e:
logging.error(f"Error closing stale tickets: {e}")
await send_heartbeat(f"Error closing stale tickets: {e}")