Allow setting SocketIO async mode from envvar or config.py (#773)

* Allow setting SocketIO async mode from envvar or config.py
This commit is contained in:
Kevin Chung
2018-12-01 19:20:36 -05:00
committed by GitHub
parent e2ff705494
commit 66c749fce6
3 changed files with 9 additions and 1 deletions

View File

@@ -134,6 +134,7 @@ def create_app(config='CTFd.config.Config'):
# If you have multiple workers you must have a shared cache # If you have multiple workers you must have a shared cache
socketio.init_app( socketio.init_app(
app, app,
async_mode=app.config.get('SOCKETIO_ASYNC_MODE'),
message_queue=app.config.get('CACHE_REDIS_URL') message_queue=app.config.get('CACHE_REDIS_URL')
) )

View File

@@ -184,12 +184,19 @@ class Config(object):
APPLICATION_ROOT: APPLICATION_ROOT:
Specifies what path CTFd is mounted under. It can be used to run CTFd in a subdirectory. Specifies what path CTFd is mounted under. It can be used to run CTFd in a subdirectory.
Example: /ctfd Example: /ctfd
SOCKETIO_ASYNC_MODE:
Specifies what async mode SocketIO should use. The simplest but least performant option is 'threading'.
Switching to a different async mode is not recommended without the appropriate load balancing mechanisms
in place and proper understanding of how websockets are supported by Flask.
https://flask-socketio.readthedocs.io/en/latest/#deployment
''' '''
REVERSE_PROXY = os.getenv("REVERSE_PROXY") or False REVERSE_PROXY = os.getenv("REVERSE_PROXY") or False
TEMPLATES_AUTO_RELOAD = (not os.getenv("TEMPLATES_AUTO_RELOAD")) # Defaults True TEMPLATES_AUTO_RELOAD = (not os.getenv("TEMPLATES_AUTO_RELOAD")) # Defaults True
SQLALCHEMY_TRACK_MODIFICATIONS = (not os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS")) # Defaults True SQLALCHEMY_TRACK_MODIFICATIONS = (not os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS")) # Defaults True
UPDATE_CHECK = (not os.getenv("UPDATE_CHECK")) # Defaults True UPDATE_CHECK = (not os.getenv("UPDATE_CHECK")) # Defaults True
APPLICATION_ROOT = os.getenv('APPLICATION_ROOT') or '/' APPLICATION_ROOT = os.getenv('APPLICATION_ROOT') or '/'
SOCKETIO_ASYNC_MODE = os.getenv('SOCKETIO_ASYNC_MODE') or 'threading'
''' '''
=== OAUTH === === OAUTH ===

View File

@@ -2,4 +2,4 @@ from flask_socketio import SocketIO
# The choice to use threading is intentional to simplify deployment. # The choice to use threading is intentional to simplify deployment.
# At the moment it is not recommended to build full-duplex systems inside CTFd. # At the moment it is not recommended to build full-duplex systems inside CTFd.
socketio = SocketIO(async_mode='threading') socketio = SocketIO()