googlecodelabs / gcf-gmail-codelab

Apache License 2.0
19 stars 18 forks source link

Stops working after few days #8

Open deniss-y opened 4 years ago

deniss-y commented 4 years ago

Hey guys! Thanks for great tutorial it was really helpful to me and works well, except one moment... cloud function stops working after 3-4 days. Could someone tell me what could be the reason of this?

Thanks in advance

ahmaxed commented 4 years ago

You would need to re-watch that gmail at least every week.

The best way to comes to mind is to have a separate function that runs the following on a schedule ( cron).

const setUpGmailPushNotifications = (email, pubsubTopic) => {
  const GCP_PROJECT = process.env.GCP_PROJECT;

  return gmail.users.watch({
    userId: email,
    requestBody: {
      labelIds: ["INBOX"],
      topicName: `projects/${GCP_PROJECT}/topics/${pubsubTopic}`,
    },
  });
};