Creating cloud tasks by providing task name to the request.
req = taskspb.CreateTaskRequest{
Parent: queueID,
Task: &taskspb.Task{
Name: taskName,
MessageType: &taskspb.Task_HttpRequest{
HttpRequest: &taskspb.HttpRequest{
HttpMethod: taskspb.HttpMethod_POST,
Url: url,
},
}, ScheduleTime: ts,
},
}
Sometimes there are scenarios we need to create tasks for the same id(task name) which was completed recently.
While trying to create cloud task with recently completed cloud task name/id the task is not getting created. Seeing NOT_FOUND error.Logs from task creation log. If i try the same after a day, the task is getting created.
{
scheduleTime: "2021-10-15T16:15:09Z"
status: "NOT_FOUND"
targetAddress: "ENDPOINT"
targetType: "HTTP"
}
I Narrowed down this issue to a particular scenario, When I create a task it is possible more than 1 task could be created for the same job. Thanks to the de-duplication, the queue returns ALREADY EXISTS error. This works as expected. The first task got created and called the endpoint and succeeded.
409 The task cannot be created because a task with this name existed too recently. For more information about task de-duplication see https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks/create#body.request_body.FIELDS.task.
Issue: After some amount of time if I create a new task with the same task name/id(data got changed ,need to process with this new task. The task endpoint has to trigger and process this changed data) , i am seeing the above error. In the cloud console i see no running tasks with this task name. Even i tried ListTasks api to get the current tasks in the queue.
Found the issue from one of the other answers from stack overflow. Issue is if the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1hour after the original task was deleted or executed.