diff --git a/nephthys/__main__.py b/nephthys/__main__.py index 28efbd5..f0f5add 100644 --- a/nephthys/__main__.py +++ b/nephthys/__main__.py @@ -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()) diff --git a/nephthys/tasks/close_stale.py b/nephthys/tasks/close_stale.py index a74154f..3e993bf 100644 --- a/nephthys/tasks/close_stale.py +++ b/nephthys/tasks/close_stale.py @@ -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}")