Closed jnowaczek closed 2 years ago
Even if you managed to remove the tasks in queue for Redis a worker could have already been started. So you would need to check if the attack still exists right before you commit the result (preferably in the same transaction). Of course removing the existing tasks in the queue for the attack would be a good optimization. (might be easier to ignore them on the worker side?)
I went with ignoring them on the worker side, I figured the only way to do this without introducing a race condition was to catch the error when the result was being inserted with an invalid foreign key.
One side effect of this is other database errors that share the IntegrityError class might get handled by the try-except I added, but I don't think that's a big problem? The previous behavior in that case would be to crash the worker, but now it will log the exception and discard the problematic result.
Ref Issue #114
This PR adds a new Admin interface page, the Attacks page. It's basically the same as the user-facing Attacks page but it provides the ability to delete attacks:
After confirming the deletion request, all results for a given attack are deleted from the database along with the attack entry. A toast notification reports the number of results deleted:
I wasn't sure (and don't have an easy way to test) if deleting pending scoring tasks would be necessary. I'm guessing it is, I bet a pending scoring task would create a new result for an attack that doesn't exist and break things... I briefly looked into deleting the task from Redis which shouldn't be too hard, otherwise maybe forcing a rescore would avoid this problem? I'm open to suggestions on how to proceed!