0

i tried following this guide from this answer https://stackoverflow.com/a/51909724/11833020, To execute a cron job with firebase realtime database on https://cron-job.org/ but it just fails everytime.

I'm getting a error that goes like this "Location: https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttp..."

Does cron jobs with realtime database also needs a blaze plan or what?

EDITED: Ok according to @DougStevenson answer i went and double check everything and there was a small error in the index.js and i fixed it and everything executed fine from cloud functions log and but nothing gets deleted from the database, I just changed the code from the above link to suit my database structure e.g :

exports.removeOldMessages = functions.https.onRequest((req, res) => {
    const timeNow = Date.now();
    const messagesRef = admin.database().ref('/messages/{user_id}/{passed_id}');
    messagesRef.once('value', (snapshot) => {
        snapshot.forEach((child) => {
            if ((Number(child.val()['time']) + Number(child.val()['duration'])) <= timeNow) {
                child.ref.set(null);
            }
        });
    });
    return res.status(200).end();
});

As you can see from the image this is how my database is structured, is that not how my code must look like in the index.js?

https://i.stack.imgur.com/l2Qgb.jpg

for the record i have zero programming knowledge in javascript i just read firebase docs on it, I'm just a beginner android developer any help or suggestions is welcomed. Thanks

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • HTTP function should only send a result after all the asynchronous work is complete. Right now, you are sending a result before anything completes (since `once()` is asynchronous), which is terminating the function early. You will have to pay attention to the promises returned by `once()` and `set()`. You should also probably not use the callback form of `once()` and instead chain off the promise it returns. – Doug Stevenson May 01 '20 at 00:35
  • @DougStevenson Thanks again once more, to be honest i only understand 20% of what you just said. Now how should i rewrite the above code snippet to only send a result once everything is completed? – Ṝøẍịn Vḵ ŠoIɳfḹűếïạḹ May 01 '20 at 10:53

0 Answers0