Skip to content

[BUG] in sample: quickstarts/taskqueues-backup-images/functions/index.js #1002

Open
@ddave09

Description

@ddave09

Which sample has a bug?

quickstarts/taskqueues-backup-images/functions/index.js

I have created my own queue with minor modifications provided in the Failing Function code used section. If someone can please help resolve the issue, I would really appreciate it.

Sample name or URL where you found the bug
quickstarts/taskqueues-backup-images/functions/index.js

How to reproduce the issue

  • 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)

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.

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.

Debug output

{"severity":"ERROR","message":"Unhandled error FirebaseFunctionsError: Queue does not exist.\n    at FirebaseFunctionsError.FirebaseError [as constructor] (/Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)\n    at FirebaseFunctionsError.PrefixedFirebaseError [as constructor] (/Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)\n    at new FirebaseFunctionsError (/Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-admin/lib/functions/functions-api-client-internal.js:269:28)\n    at FunctionsApiClient.toFirebaseError (/Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-admin/lib/functions/functions-api-client-internal.js:243:16)\n    at /Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-admin/lib/functions/functions-api-client-internal.js:101:25\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async /Users/darshitdave/Documents/Workspace/youvest/youvest/functions/lib/src/index.js:182:5\n    at async /Users/darshitdave/Documents/Workspace/youvest/youvest/functions/node_modules/firebase-functions/lib/common/providers/https.js:407:26\n    at async runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:564:9)\n    at async runHTTPS (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:590:5) {\n  errorInfo: {\n    code: 'functions/failed-precondition',\n    message: 'Queue does not exist.'\n  },\n  codePrefix: 'functions'\n}"}

Screenshots

Expected behavior

The task should be enqueued under executeOrders queue.

Actual behavior

Error message: Unhandled error FirebaseFunctionsError: Queue does not exist. even when the queue executeOrders exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions