How can to put two crons into methods correctly?

Viewed 37

I stuck with problem, how correctly put this two crons into methods?

exampleCron1:

  module.exports = functions.pubsub
  .schedule("0 0 12 * *")
  .timeZone("")
  .onRun(async () => {
    const startDate = startOfDate();
    const endDate = endOfDate();
    const dateBefore = dateBeforeGameDay();
    let listGameOrders = await getGameOrdersForEmailing(startDate, endDate);
      return !finishedGameOrdersStatusIds.includes(order.GameStatus);
    });
    let rows = finishGameOrdersStatus
      .map(
        (id) =>
          `</td><td>${game.id}</td></tr>`
      )
 sentGameHtmlEmail(statusGameOrdersView);
  });

exampleCron2:

const processGamerReminderEmail = async (gamerOrders: OrderData[]) => {
  const gamerId = firstOrder
    ? firstGameOrder.gamerId
      ? firstGameOrder.gamerId
      : ""
    : "";
  const gamerData = await (await gamer.doc(gamerId).get()).data();
  return await sentGameHtmlEmail(
    gamerReminderEmail
  );
};
module.exports = functions.pubsub
  .schedule("0 0 12 * *")
  .timeZone("")
  .onRun(async () => {
    const startDate = startOfDate();
    const endDate = endOfDate();
    const dateBefore = dateBeforeGameDay();
    const finalizedStatusDayBefore = [
    ];
    return await Promise.all(
      _.map(orderedByGamerId, (gameOrders: OrderData[]) => {
        return processGamerReminderEmail(gameOrders);
      })
    );
  });

And I don't understand how write methods correctly

I thought it should look something like this :

newGameEmails(()==>{
exampleСron1(),
exampleCron2()})
1 Answers

It looks like you're not actually returning a function from the cron modules. Like this you're returning the output of the whole functions.pubsub.schedule(… chain.

module.exports should return a function, like so:

module.exports = function exampleCron() {
    return functions.pubsub // and so on…
}

Please know that there aren't really enough details in your question to properly understand what's going on in your app like this. If you don't mind, please update your question to include details like what exactly you are trying and what when you try to call the functions, etc…

Related