Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 861
abderrahman turki Avatar asked Oct 18 '25 11:10

abderrahman turki


1 Answers

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}`);
like image 118
Nestor Solalinde Avatar answered Oct 21 '25 02:10

Nestor Solalinde