Как переопределить конфигурацию повторных попыток для клиента облачных задач Google Node.js
Я пытался выяснить, есть ли способ повторить функцию createTask. Причина в том, что я продолжаю время от времени сталкиваться с ошибкой превышения крайнего срока, вот так:
Ошибка: 4 DEADLINE_EXCEEDED: Превышен крайний срок в Object.exports.createStatusError (/srv/node_modules/grpc/src/common.js:91:15) в Object.onReceiveStatus (/srv/node_modules/grpc/srinter/cli):28) в InterceptingListener._callNext (/srv/node_modules/grpc/src/client_interceptors.js:568:42) в InterceptingListener.onReceiveStatus (/srv/node_modules/grpc/src/client_6) (call)6 /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
}
}
};
Увидеть:
- https://googleapis.github.io/gax-nodejs/global.html
- https://googleapis.github.io/gax-nodejs/global.html
- https://googleapis.github.io/gax-nodejs/global.html
Но я думаю, что лучше установить параметры повтора с помощью cli.
Увидеть: