Skip to content

Commit 71efcbd

Browse files
committed
Switch to a cross-worker redis cache for accessy caches. Switch back to sync workers to avoid db deadlocks.
1 parent 0ae7db9 commit 71efcbd

File tree

9 files changed

+173
-123
lines changed

9 files changed

+173
-123
lines changed

api/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ flask
33
flask_cors
44
sqlalchemy~=2.0.0
55
gunicorn
6-
gunicorn[gevent]
76
cryptography
87
rocky>=1,<2
98
PyMySQL
109
requests
10+
redis
1111
python-dotenv
1212
bcrypt
1313
stripe==7.8.2
@@ -22,6 +22,7 @@ types-python-dateutil
2222
types-requests
2323
types-markdown
2424
types-PyMySQL
25+
types-redis
2526
markdown
2627
NamedAtomicLock
2728
dataclasses_json

api/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ fi
1818
echo "initializing and migrating db"
1919
python3 ./init_db.py
2020

21-
exec gunicorn ${GUNICORN_FLAGS} --access-logfile - --log-level info --error-logfile - --worker-class gevent --workers=${GUNICORN_WORKERS} -b :80 api:app
21+
exec gunicorn ${GUNICORN_FLAGS} --access-logfile - --log-level info --error-logfile - --worker-class sync --workers=${GUNICORN_WORKERS} -b :80 api:app

api/src/accessy_syncer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any
88

99
import schedule
10+
from multiaccessy.accessy import accessy_session
1011
from multiaccessy.sync import sync
1112
from rocky.process import log_exception, stoppable
1213
from service.config import get_mysql_config
@@ -60,6 +61,13 @@ def daily_job() -> None:
6061
scheduled_sync()
6162

6263

64+
def hourly_job() -> None:
65+
if accessy_session is not None:
66+
# Refresh the pending invitations cache regularly to avoid slowing down
67+
# any user-facing pages that rely on it
68+
accessy_session.refresh_pending_invitations()
69+
70+
6371
def main() -> None:
6472
with log_exception(status=1), stoppable():
6573
parser = ArgumentParser(
@@ -91,6 +99,7 @@ def main() -> None:
9199

92100
case x if x == COMMAND_SCHEDULED:
93101
schedule.every().day.at("04:00").do(daily_job)
102+
schedule.every().hour.do(hourly_job)
94103

95104
while not exit.is_set():
96105
schedule.run_pending()

0 commit comments

Comments
 (0)