Pool pubsub connections for notifications (#1626)

* Add a `listen()` method to `CTFd.utils.events.EventManager` and `CTFd.utils.events.RedisEventManager`. 
  * This method should implement subscription for a CTFd worker to whatever underlying notification system there is. This should be implemented with gevent or a background thread.
  * The `subscribe()` method (which used to also implement the functionality of the new `listen()` function) now only handles passing notifications from CTFd to the browser. This should also be implemented with gevent or a background thread. 
* Pool PubSub connections to Redis behind gevent. This improves the notification system by not having a pubsub connection per browser but instead per CTFd worker. This should reduce the difficulty in deploying the Notification system.
* Closes #1622 
* Make gevent default in serve.py and add a `--disable-gevent` switch in serve.py
* Revert to recommending `serve.py` first in README. `flask run` works but we don't get a lot of control.
* Add `tenacity` library for retrying logic
* Add `pytest-sugar` for slightly prettier pytest output
This commit is contained in:
Kevin Chung
2020-09-01 12:37:03 -04:00
committed by GitHub
parent f628f26495
commit 2bc66c1ecb
7 changed files with 157 additions and 61 deletions

View File

@@ -1,4 +1,3 @@
from CTFd import create_app
import argparse
parser = argparse.ArgumentParser()
@@ -6,7 +5,20 @@ parser.add_argument("--port", help="Port for debug server to listen on", default
parser.add_argument(
"--profile", help="Enable flask_profiler profiling", action="store_true"
)
parser.add_argument(
"--disable-gevent",
help="Disable importing gevent and monkey patching",
action="store_false",
)
args = parser.parse_args()
if args.disable_gevent:
print(" * Importing gevent and monkey patching. Use --disable-gevent to disable.")
from gevent import monkey
monkey.patch_all()
# Import not at top of file to allow gevent to monkey patch uninterrupted
from CTFd import create_app
app = create_app()