question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Revise email-users example to handle multiple function executions for a single user

See original GitHub issue

I’m using the code from the sample here: https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users

onCreate is sometimes triggered multiple times for the same user. Most of the time it is triggered once, but sometimes it is triggered two times or even 7 times (which happened yesterday). exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {

No errors in the log, just the normal debug statements and the text output from console.log('New welcome email sent to:', email);

If I choose “View all from this execution”, all 7 are shown, so they come from the same execution.

7 emails are also sent, so it’s not just the debug output.

Only 1 account is created.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brianchirlscommented, Dec 16, 2018

According to Firebase engineer @laurenzlong, multiple executions is expected behavior and functions should be idempotent. Sending an email is not idempotent.

Can we please have this issue re-opened? It’d be helpful to have the example show how to ensure an email doesn’t get sent two or more times.

Thanks.

0reactions
jamieoliveredwardscommented, Jan 4, 2019

For anyone having a similar issue I found this documentation here for Google Cloud Functions which explains http functions are called at most once and background functions are called at least once.

The solution I found is to just have a standalone http function which can be called by a POST request with the data you want to handle.

Only consideration with this method is CORS, which will send two requests to the function unless you’re careful with the content of your POST request. More information is available here.

I appreciate it’s not that elegant but due to the nature of Cloud Functions I can’t see another way to resolve this.

I’m a newbie here so apologies if any of this is unhelpful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Send email using Lambda and Amazon SES - AWS
To send email from a Lambda function using Amazon SES, do the following: 1. Create an AWS Identity and Access Management (IAM) policy...
Read more >
Outlook email template: 10 quick ways to create and use
In-depth tutorial: How to create and use Outlook email templates ... shortcuts that allow performing multiple actions with a single command.
Read more >
Azure Functions best practices | Microsoft Learn
You can use the following ARM template examples to help correctly configure ... such as managing triggers and logging function executions.
Read more >
Understand How Metadata Works in User Profiles
Use Rules. Rules are JavaScript functions executed as part of the Auth0 authentication process (prior to authorization). Using rules, you can read, create ......
Read more >
Managing Users
To manage users, you must have one of the following roles: User Manager; User Administrator; Circulation Desk Manager; Circulation Desk ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found