DEADLINE_EXCEEDED
从 Node.js 客户端向 Google Cloud Tasks 添加任务时,我偶尔会遇到一个错误。我只尝试在 for 循环中添加 17 个任务。不知道为什么偶尔会发生这种情况,有时效果很好!
这是详细的错误日志:
Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
at Object.callErrorFromStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
at Http2CallStream.outputStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:115:74)
at Http2CallStream.maybeOutputStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:154:22)
at Http2CallStream.endCall (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
at Http2CallStream.cancelWithStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:443:14)
at Timeout.<anonymous> (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/deadline-filter.js:59:28)
at listOnTimeout (internal/timers.js:549:17) {
code: 4,
details: 'Deadline exceeded',
metadata: Metadata { internalRepr: Map {}, options: {} }
}
我以为我达到了一些配额。但在检查时,它们都没有超过。
这是我创建队列的方式(更新插入):
const client = require('./client');
module.exports = async (queue_name, concurrent) => {
return client.updateQueue({
queue: {
name: client.queuePath(
process.env.GCP_PROJECT,
process.env.GCP_QUEUE_LOCATION,
queue_name,
),
rateLimits: {
maxConcurrentDispatches: concurrent,
maxDispatchesPerSecond: concurrent,
maxBurstSize: 100,
},
retryConfig: {
maxAttempts: 3,
unlimitedAttempts: false,
maxRetryDuration: {
seconds: 3600,
},
minBackoff: {
seconds: 60,
},
maxBackoff: {
seconds: 300,
},
maxDoublings: 3,
},
},
});
};
这是我添加任务的方式:
const client = require('./client');
module.exports = async (queue_name, url, config) => {
return client.createTask({
parent: client.queuePath(
process.env.GCP_PROJECT,
process.env.GCP_QUEUE_LOCATION,
queue_name,
),
task: {
httpRequest: {
httpMethod: 'POST',
headers: {
'Content-Type': 'application/json',
},
url: `${process.env.OPTIMIZER_URL}/optimize-page`,
body: Buffer.from(JSON.stringify({ url, config })).toString(
'base64',
),
},
},
});
};