【问题标题】:How to override the retry configuration for Google Cloud Tasks Node.js Client如何覆盖 Google Cloud Tasks Node.js 客户端的重试配置
【发布时间】:2019-04-08 16:06:36
【问题描述】:

我一直在尝试探索是否有办法重试createTask function。原因是因为我不时遇到截止日期超出错误,如下所示:

错误:4 DEADLINE_EXCEEDED:Object.exports.createStatusError (/srv/node_modules/grpc/src/common.js:91:15) 在 Object.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors. js:1204:28) 在 InterceptingListener._callNext (/srv/node_modules/grpc/src/client_interceptors.js:568:42) 在 InterceptingListener.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:618:8)在回调(/srv/node_modules/grpc/src/client_interceptors.js:845:24)

阅读createTask函数背后的代码,我发现configuration的默认超时时间只有10秒。

目前,我试图通过这样做将超时时间延长到 30 秒(我认为这是最大值):

try {
  console.log("Sending task %j", task);
  const callOptions = {
    timeout: 30000
  };
  // Send create task request.
  const [response] = await client.createTask(request, callOptions);
  const name = response.name;
  console.log(`Created task ${name}`);
} catch (error) {
  console.error("CREATE_TASK_ERROR::", error);
}

而且它似乎有效。但是,如果 API 无法在 30 秒内响应,我也想介绍一下这种情况。

我试过这段代码:

try {
  console.log("Sending task %j", task);
  const callOptions = {
    timeout: 2000, // I've set it to 2 seconds to be able to reproduce the deadline exceeded error easily
    retry: {
      initial_retry_delay_millis: 100,
      retry_delay_multiplier: 1.3,
      max_retry_delay_millis: 60000,
      initial_rpc_timeout_millis: 20000,
      rpc_timeout_multiplier: 1.0,
      max_rpc_timeout_millis: 20000,
      total_timeout_millis: 300000
    }
  };
  // Send create task request.
  const [response] = await client.createTask(request, callOptions);
  const name = response.name;
  console.log(`Created task ${name}`);
} catch (error) {
  console.error("CREATE_TASK_ERROR::", error);
}

但我没有看到 createTask 正在重试。但根据here 的评论,我们应该能够覆盖包括重试在内的默认设置。

我做错了什么?请帮忙。

【问题讨论】:

    标签: javascript node.js google-api google-cloud-tasks


    【解决方案1】:

    看来 callOptions 是错误的。

      const callOptions = {
        timeout: 2000, // I've set it to 2 seconds to be able to reproduce the deadline exceeded error easily
        retry: {
          backoffSettings: {
            initialRetryDelayMillis: 100,
            retryDelayMultiplier: 1.3,
            maxRetryDelayMillis: 60000,
            initialRpcTimeoutMillis: 20000,
            // rpc_timeout_multiplier: 1.0,  not exists
            maxRpcTimeoutMillis: 20000,
            totalTimeoutMillis: 300000
          }
        }
      };
    

    见:

    但我认为使用 cli 设置重试参数更好。

    见:

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 1970-01-01
      • 2018-07-27
      • 2020-01-26
      • 2021-06-19
      • 1970-01-01
      • 2021-07-05
      • 2021-09-10
      • 1970-01-01
      相关资源
      最近更新 更多