From 0150bb5b30de7dab758310942a0ce0a3511e2c7f Mon Sep 17 00:00:00 2001 From: DamiCassinotti Date: Mon, 8 Mar 2021 20:29:20 -0300 Subject: [PATCH] Cancelation actions --- src/common/client.py | 12 ++++++++++++ src/common/communicator.py | 1 + src/common/operations_manager.py | 10 ++++++++-- src/config/connection.py | 2 +- src/main.py | 5 +++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/common/client.py b/src/common/client.py index c0b5994..409bad3 100644 --- a/src/common/client.py +++ b/src/common/client.py @@ -113,3 +113,15 @@ def ping(self, op_id, params, credits_): ) self.operations_manager.add_operation(operation) + + def delete(self, op_id, params, credits_): + print(f"Deleting operation ${op_id}") + operation = Operation( + op_id, + None, + credits_, + params["cron"], + params["times_per_minute"], + params["stop_time"] + ) + self.operations_manager.cancel_operation(operation) diff --git a/src/common/communicator.py b/src/common/communicator.py index 71a17c3..cf4b291 100644 --- a/src/common/communicator.py +++ b/src/common/communicator.py @@ -26,6 +26,7 @@ def add_operation(self, operation): ]) def finish_operation(self, operation): + print(f"Finishing operation with id: ${operation.id}") self.operations_queue.put([ NEW_DATA, FINISHED, diff --git a/src/common/operations_manager.py b/src/common/operations_manager.py index fabbb09..1440615 100644 --- a/src/common/operations_manager.py +++ b/src/common/operations_manager.py @@ -171,15 +171,21 @@ def schedule_operation(self, operation): if is_over(operation): print("Operation has to stop due to finish date") - self.remove_cron_task(operation) - self.communicator.finish_operation(operation) + self.cancel_operation(operation) return print("Jobs all set") def remove_cron_task(self, operation): + print(f"Removing crontab jobs with op_id: ${operation.id}") with CronTab(user=True) as cron: job_iter = cron.find_comment(operation.id) for job in job_iter: + print(f"Found a contab job to delete ${job}") cron.remove(job) + + def cancel_operation(self, operation): + self.remove_cron_task(operation) + self.communicator.finish_operation(operation) + diff --git a/src/config/connection.py b/src/config/connection.py index 24f0388..5a7bd41 100644 --- a/src/config/connection.py +++ b/src/config/connection.py @@ -1,4 +1,4 @@ -HOST = "ws://192.168.0.235:5000" +HOST = "ws://192.168.100.8:5000" # Delay between retries to reconnect in first instance DELAY_BETWEEN_RETRY = 5 RESULT_FOLDER = "../safe_storage/results/" diff --git a/src/main.py b/src/main.py index 9138687..ec8dc18 100644 --- a/src/main.py +++ b/src/main.py @@ -39,6 +39,11 @@ def on_traceroute(data): @client.sio.on('ping') def on_ping(data): client.ping(data["_id"], data["params"], data["credits"]) + + @client.sio.on('delete') + def on_delete(data): + print(f"Got a delete message with params ${data}") + client.delete(data["_id"], data["params"], data["credits"]) def connect_to_server(client): token = os.getenv('TOKEN', 'token')