when running with a multi-worker deployment server, i run into rate-limiting issues. In my case i was running with gunicorn and meinheld, as i usually do for flask apps.
[2021-07-28 13:44:58 +0000] [12] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask_discord_interactions/discord.py", line 273, in update_slash_commands
response.raise_for_status()
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://discord.com/api/v9/applications/869932770145763460/guilds/457205628754984960/commands
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/main.py", line 27, in <module>
discord.update_slash_commands(guild_id=457205628754984960)
File "/usr/local/lib/python3.8/site-packages/flask_discord_interactions/discord.py", line 275, in update_slash_commands
raise ValueError(
ValueError: Unable to register commands:429 {
"global": false,
"message": "You are being rate limited.",
"retry_after": 9.517
}
[2021-07-28 13:44:58 +0000] [11] [INFO] Worker exiting (pid: 11)
[2021-07-28 13:44:58 +0000] [12] [INFO] Worker exiting (pid: 12)
Could there perhaps be some checking done to ensure that API calls are only executed once when running multiple workers? it's common for flask apps to run with many workers, so this is quite crucial.