Skip to content

Commit

Permalink
Merge branch 'main' into 67-n00-backend-adapt-to-updated-frontend-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni000 committed Mar 22, 2024
1 parent 8d56cb4 commit a9529f3
Show file tree
Hide file tree
Showing 27 changed files with 627 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/settings.json
backend/.vscode/settings.json
2 changes: 2 additions & 0 deletions backend/dps_training_k/configuration/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from helpers.invitation_logic import LevenshteinCode
from django.utils import timezone

CODE_LENGTH = 6
INVITATION_LOGIC = LevenshteinCode(CODE_LENGTH)
CURRENT_TIME = lambda: timezone.now()
39 changes: 22 additions & 17 deletions backend/dps_training_k/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
DEBUG = env.bool("DEBUG")
CORS_ORIGIN_ALLOW_ALL = DEBUG

CSRF_TRUSTED_ORIGINS = ['http://localhost:8000']
CSRF_TRUSTED_ORIGINS = ["http://localhost:8000"]

SECRET_KEY = env.str("SECRET_KEY")
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
Expand All @@ -49,6 +49,7 @@
"django.contrib.staticfiles",
"corsheaders",
"game.apps.GameConfig",
"helpers.apps.GameConfig",
"rest_framework",
"rest_framework.authtoken",
"django_celery_beat",
Expand Down Expand Up @@ -111,8 +112,8 @@
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.TokenAuthentication",
],
}

Expand All @@ -139,14 +140,18 @@
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [env.str("REDIS_URL", default="redis://localhost:6379")] # for production
},
}
if env.bool("CHANNEL_REDIS", False)
else {"BACKEND": "channels.layers.InMemoryChannelLayer"}
"default": (
{
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [
env.str("REDIS_URL", default="redis://localhost:6379")
] # for production
},
}
if env.bool("CHANNEL_REDIS", False)
else {"BACKEND": "channels.layers.InMemoryChannelLayer"}
)
}
DEFAULT_NAME_GENERATOR = DateTimeNameGenerator()

Expand All @@ -167,9 +172,9 @@
CELERY_TASK_TIME_LIMIT = 5 * 60 # TODO: Change if necessary
CELERY_TASK_SOFT_TIME_LIMIT = 60 # TODO: Change if necessary

# CELERY_BEAT_SCHEDULE = {
# "update_patients": {
# "task": "game.tasks.check_for_updates",
# "schedule": 1.0,
# },
# }
CELERY_BEAT_SCHEDULE = {
"update_patients": {
"task": "game.tasks.check_for_updates",
"schedule": 1.0,
},
}
2 changes: 2 additions & 0 deletions backend/dps_training_k/deployment/django/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -o errexit
set -o pipefail
set -o nounset
if [ "${RUN_MIGRATIONS:-0}" = "1" ]; then

python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
fi
Expand Down
47 changes: 45 additions & 2 deletions backend/dps_training_k/game/consumers/trainer_consumer.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
from .abstract_consumer import AbstractConsumer
from django.conf import settings


class TrainerConsumer(AbstractConsumer):
class TrainerIncomingMessageTypes:
EXAMPLE = "example"
CREATE_EXERCISE = "trainer-exercise-create"
EXERCISE_CREATE = "trainer-exercise-create"
TEST_PASSTHROUGH = "test-passthrough"
EXERCISE_START = "exercise-start"
EXERCISE_STOP = "exercise-stop"
EXERCISE_PAUSE = "exercise-pause"
EXERCISE_RESUME = "exercise-resume"

class TrainerOutgoingMessageTypes:
RESPONSE = "response"
EXERCISE_CREATED = "trainer-exercise-create"
TEST_PASSTHROUGH = "test-passthrough"
EXERCISE_STARTED = "exercise-start"
EXERCISE_STOPED = "exercise-stop"
EXERCISE_PAUSED = "exercise-pause"
EXERCISE_RESUMED = "exercise-resume"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -20,12 +29,24 @@ def __init__(self, *args, **kwargs):
self.handle_example,
"exercise_code",
),
self.TrainerIncomingMessageTypes.CREATE_EXERCISE: (
self.TrainerIncomingMessageTypes.EXERCISE_CREATE: (
self.handle_create_exercise,
),
self.TrainerIncomingMessageTypes.TEST_PASSTHROUGH: (
self.handle_test_passthrough,
),
self.TrainerIncomingMessageTypes.EXERCISE_START: (
self.handle_start_exercise,
),
self.TrainerIncomingMessageTypes.EXERCISE_STOP: (
self.handle_stop_exercise,
),
self.TrainerIncomingMessageTypes.EXERCISE_PAUSE: (
self.handle_pause_exercise,
),
self.TrainerIncomingMessageTypes.EXERCISE_RESUME: (
self.handle_resume_exercise,
),
}

def connect(self):
Expand All @@ -46,3 +67,25 @@ def handle_test_passthrough(self):
self.TrainerOutgoingMessageTypes.TEST_PASSTHROUGH,
message="received test event",
)

def handle_start_exercise(self):
# Start Celery
# Start all objects with zero time tracks
# Schedule phase transitions
# Stop everything using NestedEventable
pass

def handle_stop_exercise(self):
# Stop Celery
# Stop all objects with all time tracks
# Stop phase transitions
# Stop laboratory
# Stop measures
# Stop everything using NestedEventable
pass

def handle_pause_exercise(self):
pass

def handle_resume_exercise(self):
pass
Loading

0 comments on commit a9529f3

Please sign in to comment.