Reputation: 2064
I keep getting this error and not quite sure what is going on.
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)
And this is for function I created that seems to execute sometimes and then doesn't.
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' });
}
});
And the queue is simply checking is there is a match queue in a collection
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());
}
});
Upvotes: 1
Views: 2126
Reputation: 26256
Based on the error message given, the given queueFunction
has nothing to do with it as it is an error in the queueMatch
function.
Please provide the globalFunctions
and runtimeOpts
objects. Currently I can only assume that globalFunctions
is defined as import * as globalFunctions from "firebase-functions"
.
Regarding why your interval sometimes runs, it's because you are signalling that the function is ready to be terminated before any of the interval callbacks run (see below). Once a response is returned, the "function executor" is considered safe for shutting down - you shouldn't have anything important happen after sending a response.
Your code is functionally equivalent to:
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
}
});
Note: In the above code block, assume "terminate function" to mean that process.exit()
is called immediately. In reality, the "function executor" isn't terminated immediately, but your code should assume that it is.
Upvotes: 1