[BUG] 在示例中: quickstarts/taskqueues-backup-images/functions/index.js

作者: ddave09创建于 2022年6月24日更新于 2023年10月9日
标签type: bug
  • create an index.ts file for functions with the below-mentioend code. - Deploy executeOrders function to create the queue with the same name. - execute submitOrder function. - enqueue fails with message: Unhandled error FirebaseFunctionsError: Queue does not exist.

Failing Function code used (if you modified the sample)

bash
import * as functions from "firebase-functions";
import * as firebaseAdmin from "firebase-admin";
import * as firebaseFunctions from "firebase-admin/functions";
import * as serviceAccount from "../serviceAccount.json";

firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert({
    projectId: serviceAccount.project_id,
    clientEmail: serviceAccount.client_email,
    privateKey: serviceAccount.private_key,
  }),
});

export const executeOrders = functions.region(
  region,
).tasks.taskQueue({
  retryConfig: {
    maxAttempts: 2,
    minBackoffSeconds: 10,
  },
  rateLimits: {
    maxConcurrentDispatches: 1,
  },
}).onDispatch(async (data) => {
  functions.logger.info(data);
});

export const submitOrder = functions.region(
  region,
).https.onCall(async (data, context) => {
  const queue = firebaseFunctions.getFunctions().taskQueue("executeOrders");

  functions.logger.info(data);

  await queue.enqueue({"orderId": 1});
});

I also have tried to pass in the app object returned from firebaseAdmin.initializeApp to firebaseFunctions.getFunctions() as below, but still the same behavior.

bash
const firebaseAdminApp  = firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert({
    projectId: serviceAccount.project_id,
    clientEmail: serviceAccount.client_email,
    privateKey: serviceAccount.private_key,
  }),
});

export const submitOrder = functions.region(
  region,
).https.onCall(async (data, context) => {
  const queue = firebaseFunctions.getFunctions(firebaseAdminApp).taskQueue("executeOrders");

  functions.logger.info(data);

  await queue.enqueue({"orderId": 1});
});

Steps to set up and reproduce

  • Env: node@16 - TypeScript - Deploy queue executeOrders - Start function emulator or without emulator (I have tried both ways but I get the same behavior.) - From any client call submitOrder function to enqueue a task in the executeOrders queue. - Function throws an error when enqueuing the task: Unhandled error FirebaseFunctionsError: Queue does not exist. even when the queue exists.

内容来源: firebase/functions-samples