![](/img/trans.png)
[英]How to programmatically get model id from google-cloud-automl with node.js client library
[英]How to override the retry configuration for Google Cloud Tasks Node.js Client
我一直在嘗試探索是否有辦法重試createTask函數 。 原因是因為我不時會遇到截止日期超出錯誤:
錯誤:4 DEADLINE_EXCEEDED:Object.onReceiveStatus上的Object.exports.createStatusError(/srv/node_modules/grpc/src/common.js:91:15)截止日期超過(/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函數后面的代碼,我發現默認的超時配置只有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正在重試。 但根據此處的評論,我們應該能夠覆蓋默認設置,包括重試。
我究竟做錯了什么? 請幫忙。
似乎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設置重試參數更好。
看到:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.