5

I have got one functions that triggers on db update:

exports.eventAddedTrigger = functions
  .region('europe-west6')
  .firestore
  .document('users/{user_id}/events/{event_id}')
  .onCreate(async (snap, context) => {
    const event = snap.data();

    if (event) {
      const { user_id, event_id } = context.params;
      const queue = getFunctions().taskQueue('enrol');
      const signupDate = DateTime.fromSeconds(event.signupDate.seconds).minus({minutes: 2});
      const now = DateTime.local({zone: 'Europe/Zurich'})
      let scheduleDelaySeconds = Math.floor(signupDate.diff(now, 'seconds').seconds);
      if (scheduleDelaySeconds < 0) {
        scheduleDelaySeconds = 10;
      }
      functions.logger.info(`Scheduling enrollment for ${signupDate.toISO()} in ${scheduleDelaySeconds} seconds`);
      await queue.enqueue(
        { user_id, event_id },
        {
          scheduleDelaySeconds
        }
      )
    }
  });

This function triggers fine, but when it comes to enqueue-ing, I always get the following error

Error: Queue does not exist

regardless of whether I run the function emulated or in production.

The enrol function looks like this:

exports.enrol = functions
  .region('europe-west6')
  .runWith({
    timeoutSeconds: 540,
    memory: '1GB',
  })
  .tasks
  .taskQueue()
  .onDispatch(async (data) => {
    const { user_id, event_id } = data.body;
    await _enrol(user_id, event_id, db);
    functions.logger.info(`Enrolled user ${user_id} to event ${event_id}`);
  });

I have initialised my app correctly to my best knowledge:

initializeApp({
  serviceAccountId: process.env.FIREBASE_SERVICE_ACCOUNT_ID,
});

Do I have to register the queue somewhere else?

4
  • Can you also include imports and _enrol function by editing the question ? Commented Jan 3, 2023 at 8:29
  • I am facing the very same problem. Since I cannot find this problem somewhere else this might be a very recent recession. I would love some progress or ideas on this. For me I can tell from the logs that the dispatch listener is being initiated right after the deployment with the very name I am queueing to. Commented Jan 7, 2023 at 17:22
  • @sverrirarnors I know you found a different solution but could you check if the answer provided by me would have helped you? Commented Jan 9, 2023 at 8:30
  • 1
    @bastianowicz, the solution below looks promising! I'll comment and mark it as soon as I've got the chance. Commented Jan 11, 2023 at 11:53

3 Answers 3

16

I figured this out for me. If you're using non default region for your function (i.e. not us-central1) than you need to specify your queue name including your target region. The schema is defined here https://github.com/firebase/firebase-admin-node/blob/master/src/utils/index.ts#L293

So use your enqueue function like this:

await this.functions 
    .taskQueue<INotification<any>[]>(`locations/${region}/functions/${queueName}`) 
    .enqueue(data);
Sign up to request clarification or add additional context in comments.

5 Comments

Worked like a charm! Thanks so much - this is a quite poorly documented feature by Firebase so this insight is very valuable.
Does this also work for just {functionName} instead of locations/${region}/functions/${queueName} for non default regions. Because in the doc you have provided there is shown this option in or sections. And it will be also nice if you provide the reference for this method showing we can pass functionsName to taskQueue() method
I don't think it works with just functionName for non default locations. This was the whole point of this issue. But it seems I don't get your question right. Maybe you can phrase it differently again.
We are using the default location us-central1 and got the same error.
@David.C How did you resolve?
3

I know this does not directly concern the OP, but I'll add this answer for others who made the same mistake as me. You can also encounter this error if your Cloud Functions are split into groups, but do not use the full name of the queue. For example, if you have a queue named "exampleQueue" in a group named "myGroup", you should use getFunctions().taskQueue("myGroup-exampleQueue"); instead of just getFunctions().taskQueue("exampleQueue");

Comments

0

I have tried to reproduce this issue and find out you need to initializeApp with the following syntax:

import {applicationDefault, initializeApp} from "firebase-admin/app";
initializeApp({
  credential: applicationDefault(),
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
});

Where DATABASE_NAME will be databaseURL from your firebaseConfig in the console.You can get the database by visiting project settings under your apps section.

Plus you also have to enqueue the functions into queue as shown in the documentation, and make sure you enqueue your task in around 1 minute gap also you haven't included dispatchDeadlineSeconds in queue.enqueue like the one which is provided in above documentaions.

I have found the recommended doc which shows initialization of the SDK.

2 Comments

Thanks for the answer! Unfortunately, this was not the problem. I ended up solving the problem by using the more powerful Google Cloud tasks, outlined here: stackoverflow.com/questions/74309846/…
I am pretty certain that this is not an issue with the initiattion. For me both my functions (queue listener and request listener) are being instatiated. But for whatever reason the enqueue function does not seem to find the queue with the name (trippled checked that)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.