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
}
@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