I have a cloud function that triggers every minute, sending push notifications to users
export const sendScheduledNotifications = functions
.region(REGION)
.runWith({
timeoutSeconds: 540,
})
.pubsub.schedule("* * * * *")
.timeZone("Europe/Amsterdam")
.onRun(async (_) => {
const scheduledNotifications = await getNotificationsAfterDate(Date.now());
const promises = [];
if (scheduledNotifications.length > 0) {
const userIds = scheduledNotifications.map((notification) => notification.userId);
const users: AppUser[] = userIds.length == 0 ? [] : await userRepo.listUsers("id", "in", userIds);
for (const notification of scheduledNotifications) {
const user = users.find((user) => user.id === notification.userId)!;
promises.push(sendScheduledNotification(notification, user));
}
}
await Promise.all(promises);
});
However, I am encountering the following error in the Firebase console
sendScheduledNotifications
Error: Error while making request: connect ECONNREFUSED XXX.XXX.XX.XX:XXX. Error code: ECONNREFUSED
at FirebaseAppError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppError (/workspace/node_modules/firebase-admin/lib/utils/error.js:125:28)
at /workspace/node_modules/firebase-admin/lib/utils/api-request.js:211:19
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async sendScheduledNotification (/workspace/lib/index.js:1024:5)
at async Promise.all (index 0)
at async /workspace/lib/index.js:973:5
The sendScheduledNotification function looks like this
sendMulticast(tokens: string[], notificationData: PushNotificationData): Promise<admin.messaging.BatchResponse> {
const data: admin.messaging.MulticastMessage = {
data: { data: JSON.stringify(notificationData) },
tokens: tokens,
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5",
"apns-topic": "io.flutter.plugins.firebase.messaging",
},
},
};
return this.messagingInstance.sendMulticast(data);
}
What could be causing this issue?