Last active
July 15, 2022 11:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
You can create/update queue from command line.
$ gcloud tasks queues update fooTask --routing-override=service:bar-service-name
@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
I had following error without adding appEngineRouting.