introduce a concurrency limit when creating/updating/deploying functions (max 5 functions deployed at a time)
wait until a function is fully deployed before trying to deploy another one; we will still have 5 functions deploying at the same time
refactor deployEachFunction method
add more logging to know what's going on and which function is being deployed
Why do we need this?
When deploying many functions at the same time (e.g. 50 functions), we would receive a 429 error (rate limit) thrown by Scaleway API. To avoid this, do not run all API requests concurrently, but 1 by 1 (for creation because it's a fast operation) or 5 by 5 (for deployment, as this takes more time).
BTW, this is similar to how Terraform deploy resources (10 by 10), I'm not reinventing something new here.
How have you tested it?
With this serverless.yaml containing 50 functions:
Creating function func1...
Creating function func2...
[...]
Error:
Error: AxiosError: Request failed with status code 429
at manageError (/app/node_modules/serverless-scaleway-functions/shared/api/utils.js:20:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ScalewayDeploy.updateSingleFunction (/app/node_modules/serverless-scaleway-functions/deploy/lib/createFunctions.js:224:31)
at async Promise.all (index 6)
Now (interesting logs only):
[...]
Creating function func1...
Creating function func2...
Creating function func4...
[...]
Uploading source code...
Deploying Functions...
Deploying func2...
Deploying func1...
Deploying func4...
[...]
Function func4 has been deployed to https://<redacted>.scw.cloud
Waiting for func4 domains deployment...
Domains for func4 have been deployed!
Function func3 has been deployed to https://<redacted>.scw.cloud
Waiting for func3 domains deployment...
Domains for func3 have been deployed!
[...]
And command serverless deploy succeeds.
Checklist
[ ] I have reviewed this myself
[ ] There is a unit test covering every change in this PR
Summary
What's changed?
deployEachFunction
methodWhy do we need this?
When deploying many functions at the same time (e.g. 50 functions), we would receive a 429 error (rate limit) thrown by Scaleway API. To avoid this, do not run all API requests concurrently, but 1 by 1 (for creation because it's a fast operation) or 5 by 5 (for deployment, as this takes more time).
BTW, this is similar to how Terraform deploy resources (10 by 10), I'm not reinventing something new here.
How have you tested it?
With this
serverless.yaml
containing 50 functions:Then, run
serverless deploy
.Before (interesting logs only):
Now (interesting logs only):
And command
serverless deploy
succeeds.Checklist
Details