Skip to content

Commit a85e0f8

Browse files
committed
tests sur site worker
1 parent 00dbcfb commit a85e0f8

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ services:
2727
command: bash -c "python manage.py collectstatic --noinput && cd /app/src && watchmedo auto-restart -p '*.py' --recursive -- python3 ./gunicorn_run.py"
2828
environment:
2929
- DATABASE_URL=postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
30+
- PYTHONUNBUFFERED=1
3031
env_file: .env
3132
volumes:
3233
- .:/app:delegated

src/apps/competitions/tasks.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@
116116
]
117117
MAX_EXECUTION_TIME_LIMIT = int(os.environ.get('MAX_EXECUTION_TIME_LIMIT', 600)) # time limit of the default queue
118118

119+
import sys
120+
import os
119121

120122
def _send_to_compute_worker(submission, is_scoring):
123+
print("CONTAINER CHECK PID=", os.getpid(), flush=True)
124+
sys.stderr.write("STDERR TEST\n")
125+
sys.stderr.flush()
126+
127+
print("STDOUT TEST", flush=True)
128+
129+
logger.error("LOGGER ERROR TEST")
130+
131+
logger.warning("ZZZZ _send_to_compute_worker called")
121132
run_args = {
122133
"user_pk": submission.owner.pk,
123134
"submissions_api_url": settings.SUBMISSIONS_API_URL,
@@ -201,6 +212,49 @@ def _send_to_compute_worker(submission, is_scoring):
201212
time_padding = 60 * 20 # 20 minutes
202213
time_limit = submission.phase.execution_time_limit + time_padding
203214

215+
print("DJANGO VIEW REACHED", flush=True)
216+
logger.warning("test Avant try")
217+
218+
219+
try:
220+
competition = submission.phase.competition
221+
222+
user_group_ids = list(submission.owner.groups.values_list("id", flat=True))
223+
logger.debug("User %s groups ids: %s", submission.owner.pk, user_group_ids)
224+
225+
comp_user_groups_qs = (
226+
competition.participant_groups
227+
.select_related("queue")
228+
.filter(id__in=user_group_ids)
229+
)
230+
231+
group = comp_user_groups_qs.filter(queue__isnull=False).first() or comp_user_groups_qs.first()
232+
233+
if group:
234+
logger.info(
235+
"Submission %s candidate group(s) in competition %s: chosen group=%s queue=%s",
236+
submission.pk,
237+
competition.pk,
238+
group.pk,
239+
getattr(group.queue, "name", None),
240+
)
241+
242+
if group.queue:
243+
run_args["queue"] = group.queue.name
244+
competition.queue = group.queue
245+
else:
246+
logger.debug(
247+
"Submission %s owner %s: no intersection between user's groups %s and competition %s participant_groups",
248+
submission.pk,
249+
submission.owner.pk,
250+
user_group_ids,
251+
competition.pk,
252+
)
253+
254+
except Exception:
255+
logger.exception("Error while resolving competition/group for submission %s", submission.pk)
256+
257+
204258
if submission.phase.competition.queue: # if the competition is running on a custom queue, not the default queue
205259
submission.queue_name = submission.phase.competition.queue.name or ''
206260
run_args['execution_time_limit'] = submission.phase.execution_time_limit # use the competition time limit

src/apps/profiles/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,5 @@ class Meta:
363363
verbose_name_plural = "Groups"
364364

365365
def __str__(self):
366-
return self.name
366+
return self.name
367+

src/settings/base.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,52 @@
326326
# =============================================================================
327327
# Logging
328328
# =============================================================================
329+
import sys
330+
329331
LOGGING_CONFIG = None
330332

333+
LOGGING = {
334+
'version': 1,
335+
'disable_existing_loggers': False,
336+
337+
'formatters': {
338+
'verbose': {
339+
'format': '[{asctime}] {levelname} {processName} {name}:{lineno} {message}',
340+
'style': '{',
341+
},
342+
},
343+
344+
'handlers': {
345+
'console': {
346+
'class': 'logging.StreamHandler',
347+
'stream': 'ext://sys.stdout',
348+
'formatter': 'verbose',
349+
},
350+
},
351+
352+
'root': {
353+
'handlers': ['console'],
354+
'level': 'DEBUG',
355+
},
356+
357+
'loggers': {
358+
'celery': {
359+
'handlers': ['console'],
360+
'level': 'INFO',
361+
'propagate': False,
362+
},
363+
'django': {
364+
'handlers': ['console'],
365+
'level': 'INFO',
366+
'propagate': False,
367+
},
368+
'__main__': {
369+
'handlers': ['console'],
370+
'level': 'DEBUG',
371+
},
372+
},
373+
}
374+
331375

332376
# This makes Celery not override the default logger that is configured for the project
333377
@signals.setup_logging.connect

0 commit comments

Comments
 (0)