3

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?

Dejv
  • 944
  • 2
  • 14
  • 31

4 Answers4

3

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}`);
Nestor Solalinde
  • 563
  • 4
  • 15
0

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

Averi Kitsch
  • 876
  • 5
  • 16
0

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.

Danny M
  • 75
  • 7
0

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
Mauricio
  • 473
  • 5
  • 11