Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,15 @@ def dns(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)
1 change: 1 addition & 0 deletions src/common/communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/common/operations_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ojo con esto, esto se llama si el cliente tiene que reanudar un Cron porque se cayó o cuando inicia una actividad, por lo que nunca van a haber TASKs sin finalizar => finish operation siempre va a finalizar la ejecución y eliminar el scheduler, ahora, si justo te cae un cancel_operation del servidor (DELETE a /delete), es probable que te queden TASKS enviandose al servidor y todavía se vayan a enviar, esto no es tan malo pero te van a llegar nuevos resultados por más que hayas cancelado, supongo que es el comportamiento deseado

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No veo mal que se sigan enviando mediciones después del /delete, total si ya están los resultados como que no perdemos nada en mandarlas, quizás para algo sirvan

self.remove_cron_task(operation)
self.communicator.finish_operation(operation)

1 change: 1 addition & 0 deletions src/config/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
HOST = "ws://192.168.100.8:5000"
# Delay between retries to reconnect in first instance
DELAY_BETWEEN_RETRY = 5
RESULT_FOLDER = "../safe_storage/results/"
Expand Down
7 changes: 6 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ def on_traceroute(data):
@client.sio.on('ping')
def on_ping(data):
client.ping(data["_id"], data["params"], data["credits"])

@client.sio.on('dns')
def on_dns(data):
client.dns(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):
backend_url = 'ws://' + \
Expand Down