Как переопределить конфигурацию повторных попыток для Google Cloud Tasks Node.js Клиент

#javascript #node.js #google-api #google-cloud-tasks

#javascript #node.js #google-api #google-cloud-tasks

Вопрос:

Я пытался выяснить, есть ли способ повторить функцию CreateTask. Причина в том, что время от времени я продолжаю сталкиваться с ошибкой превышения крайнего срока, вот так:

Ошибка: 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) при перехватеlistener.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:618:8) при обратном вызове (/srv/node_modules/grpc/src/client_interceptors.js:845:24)

Читая код, лежащий в основе функции CreateTask, я обнаружил, что конфигурация тайм-аута по умолчанию составляла всего 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. Но, основываясь на приведенном здесь комментарии, мы должны быть в состоянии переопределить настройки по умолчанию, включая повторные попытки.

Что я делаю не так? Пожалуйста, помогите.

Ответ №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.

Смотрите: