Skip to content
Snippets Groups Projects
Commit edc869ba authored by Sven-Ove Hänsel's avatar Sven-Ove Hänsel
Browse files

added exception handling

parent db36ab89
No related branches found
No related tags found
No related merge requests found
...@@ -63,6 +63,7 @@ def load_queries_from_file(file_path): ...@@ -63,6 +63,7 @@ def load_queries_from_file(file_path):
# logging.info(f"DBMS answered in: {execution_time} ms\n") # logging.info(f"DBMS answered in: {execution_time} ms\n")
def execute_and_log_query(query_key, query): def execute_and_log_query(query_key, query):
try:
start_time = time.time() start_time = time.time()
with driver.session() as session: with driver.session() as session:
result = session.run(query) result = session.run(query)
...@@ -98,9 +99,6 @@ def execute_and_log_query(query_key, query): ...@@ -98,9 +99,6 @@ def execute_and_log_query(query_key, query):
logging.info(f"DBMS answered in: {execution_time} ms\n") logging.info(f"DBMS answered in: {execution_time} ms\n")
logging.info(f"App python answered in: {total_time} ms\n") logging.info(f"App python answered in: {total_time} ms\n")
logging.info(f"App db answered in: {total_time2} ms\n") logging.info(f"App db answered in: {total_time2} ms\n")
# Open the CSV file in append mode and write the log information # Open the CSV file in append mode and write the log information
writer = csv.writer(csv_log_file) writer = csv.writer(csv_log_file)
# Write a header if the file is newly created or empty, else append the data # Write a header if the file is newly created or empty, else append the data
...@@ -108,6 +106,9 @@ def execute_and_log_query(query_key, query): ...@@ -108,6 +106,9 @@ def execute_and_log_query(query_key, query):
if csv_log_file.tell() == 0: # If file is empty, write a header if csv_log_file.tell() == 0: # If file is empty, write a header
writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)']) writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)'])
writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time]) writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time])
except Exception as e:
logging.error(f"Failed to execute query {query_key}: {e}")
# Continue with the next query even if the current one fails
# Function to schedule and execute all queries # Function to schedule and execute all queries
def schedule_and_execute_queries(): def schedule_and_execute_queries():
......
...@@ -64,6 +64,7 @@ def load_queries_from_file(file_path): ...@@ -64,6 +64,7 @@ def load_queries_from_file(file_path):
# logging.info(f"DBMS answered in: {execution_time} ms\n") # logging.info(f"DBMS answered in: {execution_time} ms\n")
def execute_and_log_query(query_key, query): def execute_and_log_query(query_key, query):
try:
start_time = time.time() start_time = time.time()
with driver.session() as session: with driver.session() as session:
result = session.run(query) result = session.run(query)
...@@ -102,6 +103,9 @@ def execute_and_log_query(query_key, query): ...@@ -102,6 +103,9 @@ def execute_and_log_query(query_key, query):
if csv_log_file.tell() == 0: # If file is empty, write a header if csv_log_file.tell() == 0: # If file is empty, write a header
writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)']) writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)'])
writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time]) writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time])
except Exception as e:
logging.error(f"Failed to execute query {query_key}: {e}")
# Continue with the next query even if the current one fails
# Function to schedule and execute all queries # Function to schedule and execute all queries
def schedule_and_execute_queries(): def schedule_and_execute_queries():
......
...@@ -64,6 +64,7 @@ def load_queries_from_file(file_path): ...@@ -64,6 +64,7 @@ def load_queries_from_file(file_path):
# logging.info(f"DBMS answered in: {execution_time} ms\n") # logging.info(f"DBMS answered in: {execution_time} ms\n")
def execute_and_log_query(query_key, query): def execute_and_log_query(query_key, query):
try:
start_time = time.time() start_time = time.time()
with driver.session() as session: with driver.session() as session:
result = session.run(query) result = session.run(query)
...@@ -101,6 +102,9 @@ def execute_and_log_query(query_key, query): ...@@ -101,6 +102,9 @@ def execute_and_log_query(query_key, query):
if csv_log_file.tell() == 0: # If file is empty, write a header if csv_log_file.tell() == 0: # If file is empty, write a header
writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)']) writer.writerow(['Query Key', 'Start Time', 'End Time','Fetched nodes', 'Execution Time (ms)', 'Total Time (s)'])
writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time]) writer.writerow([query_key, start_time, end_time, row_count, execution_time, total_time])
except Exception as e:
logging.error(f"Failed to execute query {query_key}: {e}")
# Continue with the next query even if the current one fails
# Function to schedule and execute all queries # Function to schedule and execute all queries
def schedule_and_execute_queries(): def schedule_and_execute_queries():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment