Skip to content

Commit c37085f

Browse files
committed
feat(submit): consecutive submissions interval 20s
1 parent 39beec2 commit c37085f

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

deploy/supervisord-debug.conf

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[supervisord]
2+
logfile=%(ENV_WORKDIR)s/data/log/supervisord.log
3+
logfile_maxbytes=10MB
4+
logfile_backups=10
5+
loglevel=info
6+
pidfile=/tmp/supervisord.pid
7+
nodaemon=true
8+
childlogdir=%(ENV_WORKDIR)s/data/log
9+
10+
[inet_http_server]
11+
port=0.0.0.0:9001
12+
username=onl
13+
password=onl
14+
15+
[rpcinterface:supervisor]
16+
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
17+
18+
[unix_http_server]
19+
file=/tmp/supervisor.sock ; unix socket file
20+
21+
[supervisorctl]
22+
serverurl=unix:///tmp/supervisor.sock ; connect to supervisord through unix socket
23+
24+
[program:redis]
25+
command=redis-server --port 7777
26+
directory=%(ENV_WORKDIR)s
27+
stdout_logfile=%(ENV_WORKDIR)s/data/log/redis.log
28+
stderr_logfile=%(ENV_WORKDIR)s/data/log/redis.log
29+
stdout_logfile_maxbytes = 10MB
30+
autostart=true
31+
autorestart=true
32+
33+
[program:gunicorn]
34+
command=python3 manage.py runserver 0.0.0.0:7890
35+
directory=%(ENV_WORKDIR)s
36+
stdout_logfile=%(ENV_WORKDIR)s/data/log/onl_backend.log
37+
stderr_logfile=%(ENV_WORKDIR)s/data/log/onl_backend.log
38+
stdout_logfile_maxbytes = 10MB
39+
autostart=true
40+
autorestart=true
41+
killasgroup=true
42+
43+
[program:onl_frontend]
44+
command=node build/dev-server.js
45+
directory=%(ENV_FRONTEND)s
46+
stdout_logfile=%(ENV_WORKDIR)s/data/log/onl_fe.log
47+
stderr_logfile=%(ENV_WORKDIR)s/data/log/onl_fe.log
48+
stdout_logfile_maxbytes = 10MB
49+
autostart=true
50+
autorestart=true
51+
startsecs=5
52+
stopwaitsecs = 5
53+
54+
[program:dramatiq]
55+
command=python3 manage.py rundramatiq --processes %(ENV_MAX_WORKER_NUM)s --threads 1
56+
directory=%(ENV_WORKDIR)s
57+
stdout_logfile=%(ENV_WORKDIR)s/data/log/dramatiq.log
58+
stderr_logfile=%(ENV_WORKDIR)s/data/log/dramatiq.log
59+
stdout_logfile_maxbytes = 10MB
60+
autostart=true
61+
autorestart=true
62+
killasgroup=true

manage

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
function print_help {
44
echo "usage:"
5-
echo " ./manage [makemigrations|migrate|clean|rebuild|run|stop]"
5+
echo " ./manage [makemigrations|migrate|clean|rebuild|run|debug|stop]"
66
}
77

88
[[ $# -ne 1 ]] && print_help && exit
99

1010
cmd=$1
11+
mode="release"
1112
apps=("account" "announcement" "conf" "contest" "options" "problem" "submission")
13+
supervisor_grep="supervisord -c ./deploy/supervisord"
1214
supervisor_cmd="supervisord -c ./deploy/supervisord.conf"
15+
supervisor_debug_cmd="supervisord -c ./deploy/supervisord-debug.conf"
1316

1417
function clean {
1518
rm -rf ./data/zips
@@ -46,9 +49,13 @@ function run_onl {
4649
echo "starting ${process_num} procs"
4750

4851
# run onl
49-
if ! command pgrep -f "$supervisor_cmd" > /dev/null; then
52+
if ! command pgrep -f "$supervisor_grep" > /dev/null; then
5053
echo "running onl controller ..."
51-
FRONTEND=$FRONTEND WORKDIR=$workdir MAX_WORKER_NUM=$process_num $supervisor_cmd > /dev/null &
54+
if [[ "$mode" == "debug" ]]; then
55+
FRONTEND=$FRONTEND WORKDIR=$workdir MAX_WORKER_NUM=$process_num $supervisor_debug_cmd > /dev/null &
56+
else
57+
FRONTEND=$FRONTEND WORKDIR=$workdir MAX_WORKER_NUM=$process_num $supervisor_cmd > /dev/null &
58+
fi
5259
[[ $? -ne 0 ]] && echo "Error: fail to run onl"
5360
else
5461
echo "onl is already running"
@@ -57,7 +64,7 @@ function run_onl {
5764
}
5865

5966
function stop_onl {
60-
pkill -f "$supervisor_cmd"
67+
pkill -f "$supervisor_grep"
6168
[[ $? -eq 0 ]] && echo "stop supervisord"
6269
}
6370

@@ -80,6 +87,10 @@ case $cmd in
8087
"run" )
8188
run_onl
8289
;;
90+
"debug" )
91+
mode="debug"
92+
run_onl
93+
;;
8394
"stop" )
8495
stop_onl
8596
;;

submission/views/user.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import hashlib
33
import requests
44
import logging
5+
import time
56
from django.db import transaction
67
from django.db.models import Q
8+
from django.core.cache import cache
79

810
from account.decorators import login_required, check_contest_permission
911
from account.models import User, UserProfile
@@ -70,11 +72,17 @@ def check_contest_permission(self, request):
7072
@login_required
7173
def post(self, request):
7274
# print(request.data)
73-
data = request.data
75+
user_id = request.user.id
76+
last_submit_time = cache.get(f"last_submit_time_{user_id}")
77+
if last_submit_time:
78+
current_time = time.time()
79+
time_diff = current_time - last_submit_time
80+
if time_diff < 15:
81+
return self.error("Submissions are too frequent, please try again later")
82+
83+
cache.set(f'last_submit_time_{user_id}', time.time())
7484

75-
error = self.throttling(request)
76-
if error:
77-
return self.error(error)
85+
data = request.data
7886

7987
# get contset and check
8088
try:

0 commit comments

Comments
 (0)