首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase错误:在process.<anonymous>上使用代码16退出的进程

Firebase错误:在process.<anonymous>上使用代码16退出的进程
EN

Stack Overflow用户
提问于 2020-12-24 04:25:20
回答 1查看 1.8K关注 0票数 1

我一直搞错了,不太清楚到底是怎么回事。

代码语言:javascript
复制
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) 

这是我创建的函数,它似乎有时执行,然后不执行。

代码语言:javascript
复制
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' });
}

});

而队列只是简单地检查集合中是否有匹配队列。

代码语言:javascript
复制
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());
    }
});
EN

回答 1

Stack Overflow用户

发布于 2020-12-24 05:03:08

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

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

关于间隔期有时运行的原因,这是因为您正在发出信号,表明函数已准备好在任何间隔回调运行之前被终止(请参见下面)。一旦返回响应,"function“就被认为是安全的关闭--在发送响应后不应该发生任何重要的事件。

您的代码在功能上相当于:

代码语言:javascript
复制
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“并没有立即终止,但是您的代码应该假定它是。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65433950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档