Skip to content

Instantly share code, notes, and snippets.

@super-dog-human
Last active July 15, 2022 11:25
Show Gist options
  • Save super-dog-human/a9c50871c836b670c02c98990533bd9a to your computer and use it in GitHub Desktop.
Save super-dog-human/a9c50871c836b670c02c98990533bd9a to your computer and use it in GitHub Desktop.
If your service on app engine runnning as not "default service" and getting NOT_FOUND error, this gist will help.
func CreateTask(projectID, locationID, queueID, relativeUri, message string) (*taskspb.Task, error) {
ctx := context.Background()
client, err := cloudtasks.NewClient(ctx)
if err != nil {
return nil, err
}
defer client.Close()
queuePath := fmt.Sprintf("projects/%s/locations/%s/queues/%s", projectID, locationID, queueID)
// this setting is needed if your app engine service is not default.
appEngineRouting := &taskspb.AppEngineRouting{
Service: os.Getenv("GAE_SERVICE"),
}
req := &taskspb.CreateTaskRequest{
Parent: queuePath,
Task: &taskspb.Task{
MessageType: &taskspb.Task_AppEngineHttpRequest{
AppEngineHttpRequest: &taskspb.AppEngineHttpRequest{
HttpMethod: taskspb.HttpMethod_POST,
RelativeUri: relativeUri,
AppEngineRouting: appEngineRouting,
},
},
},
}
req.Task.GetAppEngineHttpRequest().Body = []byte(message)
createdTask, err := client.CreateTask(ctx, req)
if err != nil {
return nil, err
}
return createdTask, nil
}
@super-dog-human
Copy link
Author

super-dog-human commented Aug 5, 2021

I had following error without adding appEngineRouting.

attemptResponseLog: {
  attemptDuration: "0.016455s"
  dispatchCount: "1"
  maxAttempts: 0
  responseCount: "1"
  scheduleTime: "2021-08-04T16:32:16.465277Z"
  status: "NOT_FOUND"
  targetAddress: "POST /task_handler"
  targetType: "APP_ENGINE_HTTP"
}

@super-dog-human
Copy link
Author

You can create/update queue from command line.

$ gcloud tasks queues update fooTask --routing-override=service:bar-service-name

@Asmar-Ali
Copy link

@super-dog-human I have the exact same error. The name of my worker function is "server" and it has a route "/log_payload" that handles the task in the queue. I don't know my service name. So this update command would look like this for me: glcoud tasks queue update testqueue --routing-override=service:server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment