Set service on Google Task API - PHP

73 views
Skip to first unread message

Alisson Linneker

unread,
Jun 1, 2020, 9:02:32 AM6/1/20
to Google App Engine
I'm trying to create a task, but it is forwarded to the project's 'default' service by informing the URI in setRelativeUri().
What would be the method for defining the specific service in the project?

My Code:

require_once __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Tasks\V2\AppEngineHttpRequest;
use Google\Cloud\Tasks\V2\CloudTasksClient;
use Google\Cloud\Tasks\V2\HttpMethod;
use Google\Cloud\Tasks\V2\Task;

$client
= new CloudTasksClient();
$queueName
= $client->queueName('MyProject', 'location-id', 'MyQueue');
$httpRequest
= new AppEngineHttpRequest();

$httpRequest
->setRelativeUri('/script.php'); //Runing on 'default' service. How to change?
$httpRequest
->setHttpMethod(HttpMethod::GET);

if (isset($payload))
    $httpRequest
->setBody($payload);

$task
= new Task();
$task
->setAppEngineHttpRequest($httpRequest);

$response
= $client->createTask($queueName, $task);

printf
('Created task %s' . PHP_EOL, $response->getName());


I've tried to change the URI to /app/serviceFolder/script.php, but it does not work. Error 404 is returned in the task logs.

George (Cloud Platform Support)

unread,
Jun 1, 2020, 11:01:32 AM6/1/20
to Google App Engine
Hello Allison, 

It depends on how you set up the queue you send your tasks to. You can explicitly route all tasks in a queue to a non-default target by using appEngineRoutingOverride in a command similar to: 

gcloud tasks queues update [QUEUE_ID] --routing-override=service:[SERVICE],version:[VERSION]

This is detailed on the "Configuring Cloud Tasks queues" page

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching App Engine and Cloud Tasks. For coding and programming architecture, as well as setting up Cloud Tasks queues in your code, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help. 
Reply all
Reply to author
Forward
0 new messages