Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second-stick-of-celery #650

Open
wants to merge 30 commits into
base: live
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4286225
replace celery configuration. Note needs CELERY_BROKER_URL and CELERY…
eatyourpeas Feb 12, 2025
0c1c7b1
fix paths so that the containers actually talk to each other instead …
eatyourpeas Feb 13, 2025
6661ed1
remove async for csv_upload
eatyourpeas Feb 15, 2025
695e4a0
removeing all async from csv_upload
eatyourpeas Feb 15, 2025
261c46f
functional upload with celery
eatyourpeas Feb 15, 2025
80eda54
add tasks chord and changes to template
eatyourpeas Feb 15, 2025
84fd651
fix csv_upload transfer validation
eatyourpeas Feb 15, 2025
6fcc714
parse types from django to celery shenanigans. various workarounds to…
eatyourpeas Feb 16, 2025
19bfa74
Merge pull request #613 from rcpch:resync
eatyourpeas Feb 16, 2025
53a4bcf
remove a bunch of debugging print statements
eatyourpeas Feb 16, 2025
5c67001
adds spinner progress while uploading
eatyourpeas Feb 16, 2025
b36e1d5
now can access list of tasks in view.
eatyourpeas Feb 16, 2025
3bdad72
functioning recorder and progress bar
eatyourpeas Feb 16, 2025
f55ee64
celery settings for tests - still not working
eatyourpeas Feb 20, 2025
9e952d5
Merge remote-tracking branch 'origin/live' into second-stick-of-celery
eatyourpeas Feb 21, 2025
7392d8d
fixes pdu but does not fix the submission not arriving in the task
eatyourpeas Feb 21, 2025
9eb5cd7
celery csv_upload tests now synchronous, mostly working but not all, …
eatyourpeas Feb 22, 2025
3e7b239
we are down to 25 failed tests
eatyourpeas Feb 22, 2025
f2fe80e
eighteen fails
eatyourpeas Feb 23, 2025
dec5364
down to 14 fails
eatyourpeas Feb 23, 2025
49111f1
down to 9 fails
eatyourpeas Feb 23, 2025
826cb8f
fixes validation rules to discard type mismatch and cast to None if c…
eatyourpeas Feb 23, 2025
18c4078
now down to 8 fails. critical fields in patient form prevent patient …
eatyourpeas Feb 23, 2025
8de6c54
csv_upload tests now fixed. header parsing tests still failing
eatyourpeas Feb 23, 2025
cbefbc2
skip header tests need to think about these
eatyourpeas Feb 23, 2025
fe3b24d
skip the remaining header tests
eatyourpeas Feb 23, 2025
e57fbfb
Merge remote-tracking branch 'origin/live' into second-stick-of-celery
eatyourpeas Feb 23, 2025
8184094
rewrite header tests
eatyourpeas Feb 23, 2025
2d91aaf
make progress bigger, add value and totals to percentage
eatyourpeas Feb 23, 2025
56cf73f
add logo to progress page
eatyourpeas Feb 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ media/submissions/csv/*

project/npda/dummy_sheets/local_generated_data/*
!project/npda/dummy_sheets/local_generated_data/.gitkeep

# exclude celerybeat-schedule
celerybeat-schedule
7 changes: 7 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
}
}

# FLOWER monitoring is served from a /flower path
# currently commented out until security is established
# handle /flower* {
# reverse_proxy http://flower:8888
# }


log {
level ERROR # switch to DEBUG for more verbose logging
}
Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,49 @@ services:
image: npda-django:built # build image and save for use by other containers
depends_on:
- postgis
- redis
volumes:
- .:/app/
command: s/start-dev
restart: always

# Redis backend for Celery task scheduler
redis:
image: redis:alpine
expose:
- 6379
restart: always

# Celery worker
celeryworker:
<<: *global # this will inherit config from x-global-environment
image: npda-django:built
container_name: npda-celery-worker
command: celery -A project worker -l info
restart: always

# Flower UI for Celery tasks
flower:
<<: *global # this will inherit config from x-global-environment
image: npda-django:built
ports:
- 8888:8888
volumes:
- npda-flower-data:/data
container_name: npda-flower
command: celery -A project flower --persistent=True -url_prefix=/flower
restart: always
depends_on:
- redis
- django

# Celery scheduled tasks/cron
celerybeat:
<<: *global # this will inherit config from x-global-environment
image: npda-django:built
container_name: npda-celery-beat
command: celery -A project beat -l info
restart: always

# PostgreSQL with PostGIS extension
postgis:
Expand All @@ -44,6 +82,7 @@ services:
<<: *django # this will inherit all the settings from the django service
ports:
- 8007:8007
container_name: npda-mkdocs
command: >
sh -c "mkdocs build --config-file documentation/mkdocs.yml &&
mkdocs serve --config-file documentation/mkdocs.yml"
Expand All @@ -52,3 +91,5 @@ services:
volumes:
npda-caddy-data:
npda-postgis-data:
npda-flower-data:
npda-redis-data:
3 changes: 3 additions & 0 deletions project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ["celery_app"]
36 changes: 36 additions & 0 deletions project/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import os

from celery import Celery
from celery import Task
from django.conf import settings
import django

# Logging setup
logger = logging.getLogger(__name__)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup() # This is crucial!

app = Celery("project")

app.config_from_object("django.conf:settings", namespace="CELERY")

app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


class NPDATask(Task):
def on_failure(self, exc, task_id, args, kwargs, einfo):
print(f"Task {task_id} failed with exception: {exc}")
return super().on_failure(exc, task_id, args, kwargs, einfo)

def on_success(self, retval, task_id, args, kwargs):
pass


@app.task(bind=True)
def debug_task(self):
logger.debug("Request: {0!r}".format(self.request))


app.Task = NPDATask
1 change: 0 additions & 1 deletion project/npda/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

26 changes: 20 additions & 6 deletions project/npda/forms/visit_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def clean_gluten_free_diet(self):
data = self.cleaned_data["gluten_free_diet"]
# Convert the list of tuples to a dictionary
gluten_free_diet_dict = dict(YES_NO_UNKNOWN)

if data is None or data in gluten_free_diet_dict:
return data
else:
Expand Down Expand Up @@ -950,10 +949,12 @@ def round_to_one_decimal_place(value):
"psychological_additional_support_status"
)

has_psychological_data = any([
psychological_screening_assessment_date,
psychological_additional_support_status
])
has_psychological_data = any(
[
psychological_screening_assessment_date,
psychological_additional_support_status,
]
)

if has_psychological_data and psychological_additional_support_status != 99:
measure_must_have_date_and_value(
Expand Down Expand Up @@ -1154,7 +1155,7 @@ def save(self, commit=True):
# I haven't implemented it here. The risk is that future versions of Django will add more
# behaviour that we miss out on.

if getattr(self, "async_validation_results"):
if hasattr(self, "async_validation_results"):
self.instance.bmi = self.async_validation_results.bmi

for field_prefix in ["height", "weight", "bmi"]:
Expand All @@ -1166,6 +1167,19 @@ def save(self, commit=True):
setattr(self.instance, f"{field_prefix}_centile", result.centile)
setattr(self.instance, f"{field_prefix}_sds", result.sds)

self.instance.patient = (
self.patient
) # This is the patient object that is passed to the form

# check if any of the fields have critical error codes
for field in self.errors:
if (
hasattr(self.errors[field][0], "code")
and self.errors[field][0].code == ErrorCode.CRITICAL_TYPE_MISMATCH
):
# set the field value to None to allow it to be saved
setattr(self.instance, field, None)

if commit:
self.instance.save()

Expand Down
Loading