This should be fairly simple to implement: a task cancellation button. A task that has yet to be processed could be removed from the queue with a single DELETE. We should make sure that we delete the task only if it has not been started, so some kind of locking, at the DB layer would need to happen. Maybe it could simply be based on the status:
DELETE FROM `tasks` WHERE tid = %d AND status = 'QUEUED'
Maybe a DELETE is a bit brutal and we should do this instead:
UPDATE `tasks` SET status='CANCELED' WHERE tid = %d AND status = 'QUEUED';
The cancel will succeed only if that succeeded.
The task processor should, on its side, do the following immediatly when starting processing:
LOCK TABLE `tasks` WRITE;
UPDATE `tasks` SET status='PROCESSING' WHERE tid = %d AND status = 'QUEUED';
UNLOCK TABLES;
The processor should go ahead with task processing only if the UPDATE succeeds.
Of course, those statuses are not the real thing, I just don't remember if they are INTs or strings in the database.
Comments
Comment #1
adrian commentedThis is in head now.
hosting_add_task allows you to set the status.
http://skitch.com/vertice/d1ctf/migtest4.dev-t
http://skitch.com/vertice/d1ctm/migtest4.dev-t
http://skitch.com/vertice/d1cuw/newsite.com-t
Comment #2
adrian commentedI also made it so certain tasks dont require the confirmation pop up anymore either.
Comment #3
avdp commentedHi, this is great. One small remark: Isn't 'cancel' a better describtion than 'stop'?
Since the task hasn't started yet, it's hard to stop it, and it gives the impression that you are stopping a task that is already running which could break stuff.
Comment #4
adrian commentedthis actually got changed to cancel already in head.
i needed to change the css around this so it all got aligned properly (which is why it was called 'stop' before)
Comment #5
avdp commentedok thanks. I only looked at the image, not the actual code.