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__/ __pycache__/
*.pyc *.pyc
*.cpython* *.cpython*
\ No newline at end of file *.log
\ No newline at end of file
# TODO # TODO
1. Correctly terminate program (and fix the ports) 1. Keep track of statistics needed for report
2. Timeout for unicast 2. Write report
3. Deal with node crash, correctly implement finish function 3. Perhaps start deleting stuff from the received set
4. Keep track of statistics needed for report \ No newline at end of file
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
...@@ -19,7 +19,8 @@ class _Transaction_Message_Queue_Item: ...@@ -19,7 +19,8 @@ class _Transaction_Message_Queue_Item:
priority_confirmations: int = None priority_confirmations: int = None
class TransactionDeliverer: 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.startup_client_names = client_names
self.addresses = addresses self.addresses = addresses
...@@ -145,8 +146,15 @@ class TransactionDeliverer: ...@@ -145,8 +146,15 @@ class TransactionDeliverer:
while len(self.transactions_queue) > 0 and self.transactions_queue[0].transaction_message.deliverable: while len(self.transactions_queue) > 0 and self.transactions_queue[0].transaction_message.deliverable:
transaction_to_process = self.transactions_queue.pop(0) transaction_to_process = self.transactions_queue.pop(0)
self.log(transaction_to_process)
self.transaction_executor.transaction(transaction_to_process.transaction_message.transaction) 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): def check_timeouts(self):
#print("Check timeouts") #print("Check timeouts")
while len(self.transactions_queue) > 0: while len(self.transactions_queue) > 0:
......
...@@ -27,6 +27,7 @@ class TransactionExecutor: ...@@ -27,6 +27,7 @@ class TransactionExecutor:
except InvalidTransactionError: except InvalidTransactionError:
pass pass
self.printTransactions() self.printTransactions()
def printTransactions(self): def printTransactions(self):
items = self.accounts.items() items = self.accounts.items()
items = sorted(items, key=lambda x: x[0]) items = sorted(items, key=lambda x: x[0])
......
...@@ -67,8 +67,12 @@ if __name__ == "__main__": ...@@ -67,8 +67,12 @@ if __name__ == "__main__":
identifier = sys.argv[1] identifier = sys.argv[1]
config_file = sys.argv[2] 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) 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 = Server(td, addresses[0], ports[0])
server_thread.start() server_thread.start()
...@@ -81,4 +85,7 @@ if __name__ == "__main__": ...@@ -81,4 +85,7 @@ if __name__ == "__main__":
process_inputs(td) process_inputs(td)
server_thread.end.set() server_thread.end.set()
server_thread.join() server_thread.join()
\ No newline at end of file
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