-
Notifications
You must be signed in to change notification settings - Fork 13
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
🎉 Implement scheduled event for positive TempIDs list #27
Conversation
fba3714
to
b01b78a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added an issue that I faced. 🙇
serverless.yml
Outdated
@@ -42,6 +43,11 @@ functions: | |||
path: /{proxy+} | |||
method: any | |||
cors: true | |||
schedule-main: | |||
handler: dist/schedule-main.handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shogo-mitomo
I can verify that this might not work, because I was trying to do something similar and ran into the same issue. 😢
I get the error:
[Nest] 29960 - 04/20/2020, 1:20:00 AM
[ExceptionHandler] The default Firebase app already exists.
This means you called initializeApp() more than once without providing an app name as the second argument.
In most cases you only need to call initializeApp() once.
But if you do want to initialize multiple apps,
pass a second argument to initializeApp() to give each app a unique name. +4ms
You can reproduce this error by:
- Let the cron function run successfully.
- Try to load any endpoint, ex:
http://localhost:3000/dev
.
The app will crash.
I think it's happening because both the handlers try to create
AppModule
, which tries to re-create firebase
instance each time for the lambda-main
handler and schedule-main
handler.
Hence this error message.
I'm further investigating right now how to handle this.
I guess easiest solution would be to split the handlers into mutliple
serverless.yml
files. This would mean the cron
nest app will run in different AWS Lambda
from main
nest app.
This might actually be the behavior we want because we might not want to scale up
our cron job as our main app scales up?. 🤔
@@ -42,6 +43,12 @@ functions: | |||
path: /{proxy+} | |||
method: any | |||
cors: true | |||
schedule-main: | |||
handler: dist/schedule-main.handler | |||
reservedConcurrency: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shogo-mitomo for reservedConcurrency
Does this mean that even if there are 100
lambda instances running, only 1
instance will run this cron
function? 😲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yashmurty
my understanding is:
Originally, lambda-main
and schedule-main
are separated as a Lambda Function, so they are invoked and scaled separately.
schedule-main
function does not scale when many HTTP requests come in. This is because there is no http
event defined for this function.
reservedConcurrency
is a setting to prevent the next function from being invoked while the old function is running because it takes more time to process than the interval of Cron, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, lambda-main and schedule-main are separated as a Lambda Function, so they are invoked and scaled separately.
Noted.
If that is the case, then you will not face the firebase
issue of multiple initialization as well, because each function will run on separate lambda. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
TODO
Closes #10