I’m not an expect in cloud functions so I would be happy if someone helped me with my issue here.
I’ve created a cloud function with a schedule. (I did that as a response to question I posted earlier). However, I realized that the schedule has no effect on the way the function runs. So instead of exporting schedule, I want to remove the schedule export and run it on a simple export base.
This is my code:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();
const min = "*/5 * * * *";
exports.scheduled = functions.pubsub.schedule(min).onRun(async (context) => {
const batch = database.batch();
const {docs} = await database.collection("ADSGHANA").get();
docs.map((doc) => {
const {
AdsId,
UID,
TimestampArrival,
TimestampDeparture,
PostStatus,
TimeToDelete,
StartingTime,
EndingTime,
} = doc.data();
const now = admin.firestore.Timestamp.now();
const starting = now > TimestampDeparture && now <= StartingTime;
const ending = now > TimestampArrival && now <= EndingTime;
const deleting = now > TimeToDelete;
let val = PostStatus;
if (starting && PostStatus !== "Cancelled") val = "Started";
if (ending && PostStatus !== "Cancelled") val = "Completed";
//.....the rest of my code
await batch.commit();
});
My function is working well const now = admin.firestore.Timestamp.now();
and as such the schedule of 15 minutes is no longer needed. How do I export my function without the schedule?
Recognized by Google Cloud Collective
1