我一直搞错了,不太清楚到底是怎么回事。
queueFunction
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/invoker.js:275:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.exit (internal/process/per_thread.js:167:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/logger.js:37:9)
at process.<anonymous> (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/invoker.js:271:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32)
queueMatch
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/invoker.js:275:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.exit (internal/process/per_thread.js:167:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/logger.js:37:9)
at process.<anonymous> (/layers/google.nodejs.functions-
framework/functions-framework/node_modules/@google-cloud/functions-
framework/build/src/invoker.js:271:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32) 这是我创建的函数,它似乎有时执行,然后不执行。
exports.queueFunction = globalFunctions.runWith(runtimeOpts).https.onRequest((request, response) => {
try {
challengeId = '';
console.log("Running cron challenge...")
var timesRun = 0;
var interval = setInterval(() => {
timesRun += 1;
if (timesRun === 12) {
console.log("Stopping cron challenge interval...")
clearInterval(interval);
}
console.log("Executing challenge match...")
getChallenges();
}, 5000);
response.status(200).send({ success: 'success' });
} catch (error) {
response.status(500).send({ error: 'error' });
}
});而队列只是简单地检查集合中是否有匹配队列。
db = admin.firestore();
const tourRef = db.collection('ChallengeQueue');
const snapshot = await tourRef.where('challengeId', '==', challengeId).get();
const queuedata = [];
if (snapshot.empty) {
console.log('No users online.');
return;
}
snapshot.forEach(doc => {
if (doc.id !== playerId) {
queuedata.push(doc.data());
}
});发布于 2020-12-24 05:03:08
根据给定的错误消息,给定的queueFunction与其无关,因为它是queueMatch函数中的一个错误。
请提供globalFunctions和runtimeOpts对象。目前,我只能假设globalFunctions被定义为import * as globalFunctions from "firebase-functions"。
关于间隔期有时运行的原因,这是因为您正在发出信号,表明函数已准备好在任何间隔回调运行之前被终止(请参见下面)。一旦返回响应,"function“就被认为是安全的关闭--在发送响应后不应该发生任何重要的事件。
您的代码在功能上相当于:
exports.queueFunction = globalFunctions.runWith(runtimeOpts).https.onRequest((request, response) => {
try {
challengeId = '';
console.log("Running cron challenge...")
var timesRun = 0;
var interval = 1 /* some number representing the ID of the interval */;
response.status(200).send({ success: 'success' }); // response sent, terminate function
} catch (error) {
response.status(500).send({ error: 'error' }); // response sent, terminate function
}
});注意:在上面的代码块中,假设“终止函数”意味着process.exit()被立即调用。实际上,"function“并没有立即终止,但是您的代码应该假定它是。
https://stackoverflow.com/questions/65433950
复制相似问题