millions-honey-27871
07/09/2025, 2:50 AMctx.add_shutdown_callback(_shutdown_hook)
?tall-airline-16756
07/09/2025, 2:50 AMtall-airline-16756
07/09/2025, 2:51 AMctx.add_shutdown_callback(_shutdown_hook)
, you need to store the call's start time when it begins, then calculate the duration in the shutdown callback by subtracting the start time from the current time.
Example implementation:
import time
async def entrypoint(ctx: JobContext):
call_start_time = time.time() # Store start time when call begins
async def on_shutdown():
duration = time.time() - call_start_time # Calculate duration on shutdown
<http://logger.info|logger.info>(f"Call duration: {duration:.2f} seconds")
ctx.add_shutdown_callback(on_shutdown)
This logs the call duration when the shutdown callback triggers, ensuring you have the elapsed call time.