added celery

This commit is contained in:
Alexander-D-Karpov 2022-11-04 14:51:11 +03:00
parent 8b88e97489
commit d5731ad8af
3 changed files with 6 additions and 7 deletions

View File

@ -7,6 +7,7 @@ from pathlib import Path
import magic
import numpy as np
import pydicom
from dicom import tasks
from dicom.models import Coordinate, Dicom, Project
from django.core.files import File
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
@ -45,6 +46,7 @@ def process_files(
user=user,
)
shutil.rmtree(dit_path)
tasks.process_project.apply_async(kwargs={"pk": project.pk}, countdown=3)
return project

View File

@ -1,5 +1,4 @@
from dicom.models import Dicom, Project
from dicom.tasks import process_project
from django.db.models.signals import post_save
from django.dispatch import receiver
from utils.generators import generate_charset
@ -13,7 +12,6 @@ def create_project(sender, instance: Project, created, **kwargs):
slug = generate_charset(5)
instance.slug = slug
instance.save()
process_project.apply_async(kwargs={"slug": slug})
@receiver(post_save, sender=Dicom)

View File

@ -1,10 +1,9 @@
from celery import shared_task
from dicom import services
from dicom.models import Project
from dicom.services import generate_3d_model
@shared_task()
def process_project(slug: str):
print(slug)
generate_3d_model(Project.objects.get(slug=slug))
return slug
def process_project(pk: int):
services.generate_3d_model(Project.objects.get(pk=pk))
return pk