abderrahman turki
abderrahman turki

Reputation: 129

How to edit Google Cloud task's default timeout (with http target, not app engine)?

I'm using this package to add Google Cloud tasks to my project and it works perfectly. The problem is that I can't figure out how to increase http target request timeout?

Upvotes: 3

Views: 5177

Answers (4)

Mauricio
Mauricio

Reputation: 621

If you come here using NodeJS, modify request to allow timeout up to 30 minutes like this:

request.task.dispatchDeadline = { seconds: 60 * 30 }

Works with:

@google-cloud/tasks : 3.1.2

Upvotes: 0

Danny M
Danny M

Reputation: 85

I can't comment due to lack of reputation, but the first solution is incorrect. dispatch_deadline is part of the task request, not the httpRequest. It should be moved out one level of that object.

task: {
    dispatch_deadline: 200
    httpRequest: {

    }
}

However, I tried to implement this and unfortunately the request just hangs when you add this flag. My request never goes through to creating a task. I think it is a broken feature.

Upvotes: 1

Nestor Solalinde
Nestor Solalinde

Reputation: 593

Use dispatchDeadline if you are creating a task using nodejs. Source: https://googleapis.dev/nodejs/tasks/latest/google.cloud.tasks.v2beta3.Task.html

Example implementation:

//npm install --save @google-cloud/tasks
const client = new CloudTasksClient();
const project = 'your-project-name';
const queue = 'your-queue-name';
const location = 'us-central1';
const parent = client.queuePath(project, location, queue);
const serviceAccountEmail = 'user@projectname_or_whatever.iam.gserviceaccount.com';
const url = 'http://destination_url'


const payload = JSON.stringify({ "user": "Manuel Solalinde", 'mode': 'secret mode' })
const body = Buffer.from(payload).toString('base64')
// task creation documentation: https://googleapis.dev/nodejs/tasks/latest/google.cloud.tasks.v2beta3.Task.html
const task = {
    httpRequest: {
        httpMethod: 'POST',
        url: url,
        dispatchDeadline: 30 * 60, //30 minutes
        body: body,
        headers: { "Content-type": "application/json" },
        oidcToken: {
            serviceAccountEmail,
        },
    },
};

// Send create task request.
console.log('Sending task:');
const [response] = await client.createTask({ parent, task });
console.log(`Created task ${response.name}`);

Upvotes: 3

Averi Kitsch
Averi Kitsch

Reputation: 921

The dispatch_deadline property of the Tasks object should allow you to extend the request timeout. Default is 10 minutes for HTTP targets.

Cloud Tasks Client Library Documentation for PHP

Upvotes: 0

Related Questions