Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke lambda function in pixel handler for #35 #36

Merged
merged 2 commits into from
May 11, 2020

Conversation

nelsonic
Copy link
Member

@nelsonic nelsonic commented May 7, 2020

This PR addresses issue #35
Will speed up sending email when the person authenticates or registers. 🚀

The way you can visually check that this is working is by visiting: https://dwylauth.herokuapp.com
auth-waiting-for-email

It does not "block" the UI in the Auth App it just makes the request for the "pixel" in the background.

The point is to "Wake" the https://dwylmail.herokuapp.com App so that after successfully authenticating with the Auth app, the email is sent as fast as possible. If you open the Email dashboard in a different tab you'll notice that it loads instantly:

image

Obviously this is a stop gap until we deploy all our apps to VPS: dwyl/learn-devops#59

@nelsonic nelsonic temporarily deployed to dwylmail May 7, 2020 22:07 Inactive
@codecov
Copy link

codecov bot commented May 7, 2020

Codecov Report

Merging #36 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #36   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          105       108    +3     
=========================================
+ Hits           105       108    +3     
Impacted Files Coverage Δ
lib/app_web/controllers/sent_controller.ex 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6396591...69a04b3. Read the comment docs.

lambda = System.get_env("AWS_LAMBDA_FUNCTION")
ExAws.Lambda.invoke(lambda, payload, "no_context")
|> ExAws.request(region: System.get_env("AWS_REGION"))
|> IO.inspect(label: "ExAws.Lambda ping response")
Copy link
Member

@SimonLab SimonLab May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you want to keep this IO.inspect uncommented

Suggested change
|> IO.inspect(label: "ExAws.Lambda ping response")
# |> IO.inspect(label: "ExAws.Lambda ping response")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'm happy to leave these kinds of logs in this App.
When we are paying for the storage of logs, we will have to be strict about them
and will probably have a pre-commit hook/check to not allow uncommented IO.inspect. 👍

Copy link
Member

@SimonLab SimonLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and it makes sense to "wake up" the lambda when the pixel endpoint is called.
I didn't know that lambdas could be become "inactive".

@SimonLab SimonLab merged commit b4c2c4f into master May 11, 2020
@SimonLab SimonLab deleted the ping-lambda-in-pixel-handler-issue#35 branch May 11, 2020 12:42
@nelsonic
Copy link
Member Author

@SimonLab yeah, Lambda functions also go to "sleep" after a period of inactivity to save RAM on the VM running the function. The function gets re-loaded into RAM "just-in-time" for a fresh execution but it stays "warm" for between 5 and 45 mins after that depending on the scheduler (i.e. how many people are using Lambda in your region) but that is all "black box" to the developer. We tested it extensively at TC, that's how I know about it.
https://www.jeremydaly.com/lambda-warmer-optimize-aws-lambda-function-cold-starts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants