1
votes

I have a task queue which users can push tasks onto, only one task can run at a time enforced by the concurrency setting for the queue. In some cases (e.g. long running task) they may wish to cancel a running task in order to free up the queue to process the next task.

To achieve this I have been running the task queue as a Flask application, should a user wish to cancel a task I call the delete_task method of the python client library for a given queue & task.

However, I am seeing that the underlying task continues to be processed even after the task has been deleted. Have been trying to find documentation of how Cloud Tasks handles a task being deleted, but haven't found anything concrete.

Hoping that i'd be able to listen for a signal of some sort in order to gracefully shut down the process if a deletion is received. Or that the underlying process would be killed if the parent task is deleted.

Has anyone worked with the Cloud Tasks API before? Is it correct to assume that a deleted task will cleanup any processes that are running?

1
Where are you seeing that "the underlying task continues to be processed even after the task has been deleted"? On Cloud Task? Or on the called system? Can you also precise the type of task (HTTP or AppEngine)? - guillaume blaquiere
On Cloud Task HTTP Push, does deleting a task while being dispatched stops the underlying HTTP connection? What about app engine? - Benos

1 Answers

1
votes

I don't see how a worker would be able to find out that the task it is working on has been deleted.

In the eyes of the worker, a task is an incoming Http request. I don't know how the Queue could tell that specific process to stop. I'm fairly certain that "deleting" a task just removes it from the Queue only.

You'd have to build a custom 'cancel' function that would be able to reach out to this worker.

Or this worker would have to periodically check with the Queue to see if its task still exists. https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks/get https://googleapis.dev/python/cloudtasks/latest/gapic/v2/api.html#google.cloud.tasks_v2.CloudTasksClient.get_task

I'm not actually sure what the Queue will return if you try to call 'get task' a deleted task since i don't see a 'status' property for task. Maybe it will return an error like 'task does not exist'