Skip to content
Snippets Groups Projects
Commit 111edc30 authored by Jeffrey Zhang's avatar Jeffrey Zhang
Browse files

Add basic logging

parent 45e26b7e
No related branches found
No related tags found
No related merge requests found
__pycache__/
*.pyc
*.cpython*
\ No newline at end of file
*.cpython*
*.log
\ No newline at end of file
# TODO
1. Correctly terminate program (and fix the ports)
2. Timeout for unicast
3. Deal with node crash, correctly implement finish function
4. Keep track of statistics needed for report
5. Write report
6. Deal with time.sleep in main.py
7. Perhaps start deleting stuff from the received set
\ No newline at end of file
1. Keep track of statistics needed for report
2. Write report
3. Perhaps start deleting stuff from the received set
\ No newline at end of file
......@@ -19,7 +19,8 @@ class _Transaction_Message_Queue_Item:
priority_confirmations: int = None
class TransactionDeliverer:
def __init__(self, client_names, addresses, ports) -> None:
def __init__(self, client_names, addresses, ports, logfile = None) -> None:
self.logfile = logfile
self.startup_client_names = client_names
self.addresses = addresses
......@@ -145,8 +146,15 @@ class TransactionDeliverer:
while len(self.transactions_queue) > 0 and self.transactions_queue[0].transaction_message.deliverable:
transaction_to_process = self.transactions_queue.pop(0)
self.log(transaction_to_process)
self.transaction_executor.transaction(transaction_to_process.transaction_message.transaction)
def log(self, queue_item):
if not self.logfile is None:
# Transaction ID - Generated Timestamp - Executed Timestamp
message = queue_item.transaction_message
self.logfile.write(f"{message.transaction_ID} {message.generate_timestamp} {time.time()}\n")
def check_timeouts(self):
#print("Check timeouts")
while len(self.transactions_queue) > 0:
......
......@@ -27,6 +27,7 @@ class TransactionExecutor:
except InvalidTransactionError:
pass
self.printTransactions()
def printTransactions(self):
items = self.accounts.items()
items = sorted(items, key=lambda x: x[0])
......
......@@ -67,8 +67,12 @@ if __name__ == "__main__":
identifier = sys.argv[1]
config_file = sys.argv[2]
logfile = None
if len(sys.argv) >= 4:
logfile = open(sys.argv[3], 'w')
client_names, addresses, ports = process_config(config_file)
td = TransactionDeliverer(client_names, addresses, ports)
td = TransactionDeliverer(client_names, addresses, ports, logfile)
server_thread = Server(td, addresses[0], ports[0])
server_thread.start()
......@@ -81,4 +85,7 @@ if __name__ == "__main__":
process_inputs(td)
server_thread.end.set()
server_thread.join()
\ No newline at end of file
server_thread.join()
if logfile:
logfile.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment