MbaiMburu
MbaiMburu

Reputation: 915

Cron job not working in firebase functions

I have the following cron job that I need to execute everyday at 6 and 9AM.

cron.schedule('00 00 6,9 * * 0-6', function() {
alertAllMembersWithAppointments();//executed everyday at 6 and 9AM});

When I set the timing like this

cron.schedule('* * * * * *', function() {
    alertAllMembersWithAppointments();//executed everyday at 6 and 9AM
});

it works fine and executes every minute. Please help to set the timing since it seems to me cron settings for node and linux are quite different. I am using the following requirement const cron = require("node-cron");

Upvotes: 2

Views: 2218

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599956

@sketchthat's comment isspot on with the logic here: running the cron-job each minute, likely keeps it under the timeout of the function.

But re-triggering a function like that is going to be unreliable, unless you take care of returning the right promises. If you do it correctly, it's going to work and you end up having Cloud Function that is forever active. At that point, it'll be cheaper to find a cheap node host somewhere.

For reliable time-based functions, you'll need to rely on an external trigger. See Cloud Functions for Firebase trigger on time?

Upvotes: 2

Related Questions