Google Cloud Tasks 有时似乎不可靠。我添加了一堆任务,有时这些任务没有被执行。
当我检查控制台时,它显示“队列中有 11 个任务”。但是,这些任务未在下面列出(通常显示正确)。
这是我创建队列的方式(更新插入):
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',
),
},
},
});
};
相同的代码有时有效,有时只是在执行时卡住了!