1

我正在使用这个包将 Google Cloud 任务添加到我的项目中,并且效果很好。问题是我不知道如何增加 http 目标请求超时?

4

3 回答 3

2

如果您使用dispatchDeadlinenodejs 创建任务,请使用。来源:https ://googleapis.dev/nodejs/tasks/latest/google.cloud.tasks.v2beta3.Task.html

示例实现:

//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}`);
于 2020-09-10T07:16:24.667 回答
0

Tasks 对象的dispatch_deadline属性应该允许您延长请求超时。HTTP 目标的默认值为 10 分钟。

适用于 PHP 的 Cloud Tasks 客户端库文档

于 2019-06-17T18:09:48.807 回答
0

由于缺乏声誉,我无法发表评论,但第一个解决方案是不正确的。dispatch_deadline 是任务请求的一部分,而不是 httpRequest。它应该移出该对象的一层。

task: {
    dispatch_deadline: 200
    httpRequest: {

    }
}

但是,我尝试实现这一点,不幸的是,当您添加此标志时,请求只是挂起。我的请求从不涉及创建任务。我认为这是一个损坏的功能。

于 2021-07-30T01:21:29.183 回答