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?