Firebase 错误:进程在进程结束时退出,代码为 16。<anonymous>



我一直收到这个错误,不太确定发生了什么。

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());
}
});

根据给定的错误消息,给定的queueFunction与它无关,因为它是queueMatch函数中的错误。

请提供globalFunctionsruntimeOpts对象。目前我只能假设globalFunctions被定义为import * as globalFunctions from "firebase-functions"

关于为什么您的间隔有时会运行,这是因为您在发出信号,表明函数已准备好在任何间隔回调运行之前终止(见下文(。一旦返回响应;功能执行器";被认为是安全的关闭-发送响应后不应该发生任何重要的事情。

您的代码在功能上等效于:

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
}
});

注意:在上面的代码块中,假设"终止函数";意味着立即调用CCD_ 7。事实上;功能执行器";不会立即终止,但您的代码应该假设它是终止的。

相关内容

  • 没有找到相关文章