问题描述
我需要使用云调度程序创建数千个任务。我已经完成了下面的代码,但它抛出了我
错误:4 DEADLINE_EXCEEDED:超过最后期限
exports.addTasksToQueueScheduler = functions.region('europe-west3').pubsub
.schedule('every 1 minutes')
.timeZone('Asia/Calcutta')
.onRun(async (context) => {
const query = db.collection('live_auctions').where('is_closed','==',0);
const tasks = await query.get();
if (!tasks.empty) {
const promises = []
tasks.forEach(snapshot => {
const result = snapshot.data();
var inSeconds = 0;
for(var i=0; i < result.no_of_lots; i++){
async function createTask() {
const project = 'myproject-307210';
const queue = 'auction-autobid-queue';
const location = 'europe-west1';
const payload = 'Hello,World!';
const serviceAccountEmail = "my-name@myproject-307210.iam.gserviceaccount.com";
// Construct the fully qualified queue name.
const parent = client.queuePath(project,location,queue);
const task = {
httpRequest: {
httpMethod: 'GET',url: 'https://europe-west3-myproject-307210.cloudfunctions.net/autobidLots?id=' + result.id,oidcToken: {
serviceAccountEmail,},};
if (payload) {
//task.httpRequest.body = Buffer.from(payload).toString('base64');
}
inSeconds = inSeconds + 8;
if (inSeconds) {
// The time when the task is scheduled to be attempted.
task.scheduleTime = {
seconds: inSeconds + Date.Now() / 1000
};
}
console.log('Sending task:');
console.log(task);
// Send create task request.
const request = {parent,task};
const [response] = await client.createTask(request);
console.log(`Created task ${response.name}`);
}
process.on('unhandledRejection',err => {
console.error(err.message);
process.exitCode = 1;
});
createTask();
}
});
}
});
附上错误截图。
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit
不知何故,我发现 Promise
可以帮助解决问题并终止函数。但我是 Google Cloud 和 nodejs 的新手,所以我需要帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)