js客户端的重试配置

js客户端的重试配置

本文介绍了如何覆盖Google Cloud Tasks Node.js客户端的重试配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试探索是否有一种方法可以重试 createTask函数.原因是因为我不断遇到这样的截止日期超出错误:

I've been trying explore if there's a way to retry the createTask function. The reason being is because I keep on encountering deadline exceeded error from time to time like so:

通过阅读createTask函数背后的代码,我发现默认超时配置仅为10秒.

Reading on the code behind the createTask function, I found out that the default timeout configuration was just 10 seconds.

目前,我已尝试通过以下方法将超时时间延长到30秒(我认为是最大):

At the moment, I have tried to extend the timeout to 30s (which I believe is the maximum) by doing this:

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秒之内无法响应,我也想谈一谈.

And it appears that it works. However, I would also like to cover the case if the API wasn't able to respond within 30 seconds.

我尝试了以下代码:

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被重试.但基于评论此处 ,我们应该能够覆盖默认设置,包括重试.

But I don't see the createTask being retried. But based on the comment here, we should be able to override the default settings including retries.

我做错了什么?请帮忙.

What am I doing wrong? Please help.

推荐答案

似乎callOptions是错误的.

It seems to that callOptions is wrong.

  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
      }
    }
  };

请参阅:

  • https://googleapis.github.io/gax-nodejs/global.html#CallOptions
  • https://googleapis.github.io/gax-nodejs/global.html#RetryOptions
  • https://googleapis.github.io/gax-nodejs/global.html#BackoffSettings

但是我认为使用cli设置重试参数会更好.

But I think that to set retry parameters using cli is better.

请参阅:

这篇关于如何覆盖Google Cloud Tasks Node.js客户端的重试配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:13