Store duration of http & timer functions in ms from begining of request to end

This commit is contained in:
Peter Stockings
2025-12-02 19:55:32 +11:00
parent d04b7f2120
commit 71296b1301
2 changed files with 12 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import os
import time
from dotenv import load_dotenv
# Load environment variables from .env file first, before any other imports
@@ -31,6 +32,7 @@ async def execute_timer_function_async(timer_function):
Execute a timer function asynchronously and record the invocation
"""
try:
start_time = time.time()
code = timer_function['code']
environment = timer_function['environment']
name = timer_function['name']
@@ -111,6 +113,9 @@ async def execute_timer_function_async(timer_function):
WHERE id = %s
""", [json.dumps(function_specific_env), next_run, timer_function['id']], commit=True)
# Calculate execution time in milliseconds
execution_time = (time.time() - start_time) * 1000
# Record the invocation
db.execute("""
INSERT INTO timer_function_invocations
@@ -121,7 +126,7 @@ async def execute_timer_function_async(timer_function):
response_data['status'],
json.dumps(response_data['logs']),
version_number,
response_data.get('execution_time')
execution_time
], commit=True)
except Exception as e: