Skip to content

Commit

Permalink
Add execution time to API
Browse files Browse the repository at this point in the history
  • Loading branch information
sihaelov committed Jan 14, 2018
1 parent cdd4bb4 commit 1c05727
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.py
Expand Up @@ -45,6 +45,7 @@ async def api_run_sql(request):
return web.json_response({'headers': [], 'rows': [],
'error': "Empty query"})

start_time = datetime.now()
with pyodbc.connect(db_url, timeout=60) as connection:
cursor = connection.cursor()
# connection.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
Expand All @@ -62,11 +63,15 @@ async def api_run_sql(request):
print('Error')
error = str(e)
headers = []
end_time = datetime.now()
execution_time_raw = end_time - start_time
execution_time = round(execution_time_raw.total_seconds())

return web.json_response({
'headers': headers,
'rows': rows,
'error': error
'error': error,
'execution_time': execution_time
}, dumps=functools.partial(json.dumps, default=str))


Expand Down

0 comments on commit 1c05727

Please sign in to comment.