firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Add v2 Schedule Triggers

Open colerogers opened this issue 3 years ago • 2 comments

Adds schedule triggers to the v2 namespace.

  • Replaces pub/sub with an http underlying function
  • Updated syntax to match with the other v2 triggers

This change does not add the invoker property to the container contract.

export const sch = v2.schedule.onSchedule("* * * * *", () => {});

export const sch = v2.schedule.onSchedule(
  {
    schedule: "* * * * *",
    timeZone: "utc",
  },
  () => {}
);

colerogers avatar Jul 21 '22 12:07 colerogers

Note to self: some of the types in this trigger are also going to need the Field/Expression treatment.

Berlioz avatar Jul 21 '22 19:07 Berlioz

@Berlioz I can update this PR to take the work off your plate, what example should I be looking at?

colerogers avatar Jul 22 '22 15:07 colerogers

Force merging - @inlined's comments have all been addressed.

taeold avatar Aug 25 '22 16:08 taeold

The new V2 onSchedule cloud function does not seem to have a way to set timeoutSeconds or memory options.

For instance, my V1 scheduled cloud function currently sets both using runWith(): exports.function = functions.runWith({timeoutSeconds: 300, memory: '512MB'}).pubsub.schedule('0 22 * * 0-6').onRun(() => {...});

However, the currently listed ScheduleOptions listed in the V2 documentation does not list either of these properties: https://firebase.google.com/docs/functions/beta/reference/firebase-functions.scheduler.scheduleoptions

Are these properties going to be added to ScheduleOptions?

kbi-daniel avatar Feb 03 '23 17:02 kbi-daniel

Hey @kbi-daniel! The ScheduleOptions extends the base GlobalOptions, so options like timeout and memory should be available. Eg.

exports.v2schedule = onSchedule(
    {
        // ScheduleOptions
        schedule: "every 2 minutes",
        maxBackoffSeconds: 20,
        // GlobalOptions
        memory: "1GiB",
        timeoutSeconds: 50,
    }, (event) => {
    console.log(event);
});

taeold avatar Feb 03 '23 18:02 taeold

Thanks @taeold. Worked as expected!

kbi-daniel avatar Feb 03 '23 22:02 kbi-daniel