From 10181e4d176c827afaefabe79ff8b7401741795e Mon Sep 17 00:00:00 2001 From: karthikeyan-ks Date: Mon, 6 Jan 2025 22:17:09 +0530 Subject: [PATCH] changes --- backend/api/__init__.py | 0 backend/api/admin.py | 3 +++ backend/api/apps.py | 6 ++++++ backend/api/migrations/__init__.py | 0 backend/api/models.py | 3 +++ backend/api/task.py | 9 +++++++++ backend/api/tests.py | 3 +++ backend/api/views.py | 31 +++++++++++++++++++++++++++++ backend/backend/settings.py | 4 ++++ backend/backend/urls.py | 2 ++ backend/celery.py | 16 +++++++++++++++ backend/db.sqlite3 | Bin 0 -> 131072 bytes 12 files changed, 77 insertions(+) create mode 100644 backend/api/__init__.py create mode 100644 backend/api/admin.py create mode 100644 backend/api/apps.py create mode 100644 backend/api/migrations/__init__.py create mode 100644 backend/api/models.py create mode 100644 backend/api/task.py create mode 100644 backend/api/tests.py create mode 100644 backend/api/views.py create mode 100644 backend/celery.py create mode 100644 backend/db.sqlite3 diff --git a/backend/api/__init__.py b/backend/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/admin.py b/backend/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/api/apps.py b/backend/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/backend/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/backend/api/migrations/__init__.py b/backend/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/models.py b/backend/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/backend/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/api/task.py b/backend/api/task.py new file mode 100644 index 0000000..4973e5e --- /dev/null +++ b/backend/api/task.py @@ -0,0 +1,9 @@ +from __future__ import absolute_import, unicode_literals +from celery import shared_task +import time + +@shared_task +def process_uploaded_file(file_path): + # Simulate long-running task + time.sleep(300) # Replace with actual file processing logic + return 'File processed' diff --git a/backend/api/tests.py b/backend/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/api/views.py b/backend/api/views.py new file mode 100644 index 0000000..1753789 --- /dev/null +++ b/backend/api/views.py @@ -0,0 +1,31 @@ +from django.shortcuts import render +from django.http import JsonResponse +from .tasks import process_uploaded_file +from .forms import UploadFileForm +import os + +# Create your views here. +def handle_uploaded_file(f, file_path): + with open(file_path, 'wb+') as destination: + for chunk in f.chunks(): + destination.write(chunk) + +def upload(request): + if request.method == 'POST': + form = UploadFileForm(request.POST, request.FILES) + if form.is_valid(): + file = form.cleaned_data['file'] + file_path = os.path.join('uploads', file.name) # Change 'uploads' to your desired directory + handle_uploaded_file(file, file_path) + task = process_uploaded_file.delay(file_path) + return JsonResponse({'task_id': task.id}) + + else: + form = UploadFileForm() + return render(request, 'upload.html', {'form': form}) + +from celery.result import AsyncResult + +def check_task_status(request, task_id): + task_result = AsyncResult(task_id) + return JsonResponse({'status': task_result.status, 'result': task_result.result}) diff --git a/backend/backend/settings.py b/backend/backend/settings.py index e7e2397..f152247 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'api' ] MIDDLEWARE = [ @@ -121,3 +122,6 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +CELERY_BROKER_URL = 'redis://localhost:6379/0' +CELERY_ACCEPT_CONTENT = ['json'] +CELERY_TASK_SERIALIZER = 'json' diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 5edb75c..08bda50 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -16,7 +16,9 @@ Including another URLconf """ from django.contrib import admin from django.urls import path +from api.views import upload urlpatterns = [ path('admin/', admin.site.urls), + path('upload/',upload) ] diff --git a/backend/celery.py b/backend/celery.py new file mode 100644 index 0000000..312fe2e --- /dev/null +++ b/backend/celery.py @@ -0,0 +1,16 @@ +from __future__ import absolute_import, unicode_literals +import os +from celery import Celery + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + +app = Celery('backend') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# Namespace 'CELERY' means all celery-related configs must start with 'CELERY_' +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks() diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..a594b9dd8ce1a79574b6354ec79d72b774833428 GIT binary patch literal 131072 zcmeI5TWlNIdB-{8kQ617M^}#;TNXvHcFoF?IJ`;pHtlM?imj|y-u0y$7Y(LEawOB? zMJ6d<5FjWOZxd|NJ|swh7HGFG1rj6==_SZR5+F!X6m8L_Es_Ggq-dYEEs&;Y(dMBI z(C-}1aE3#QQj{35g+CWN;+gZEZ~o_ZE;I9;8S};)S4&MJx?QVR^ky{W8S_Yz=cQ=W z-$Xtcc{%*U@K?hR!s*bvp?5+*9~vM1 z*63SggbxUS00@8p2!H?xfB*=9Ko^13gwHd(u--5ljZ&@JNF)-fR;reoCB2+XBr{71 zbt#dJs@aRl?8QuGSxscJs(NMI=b3(UUEgcoA^W7Jmzzdi+iTEfyHsy9wW?k*w2J;v zD;w3F=AC|?5}9N!nRsc8JYBXtsoLIdQEwXBZoT&Kk+y5pE2XxsUJvQzTy`y+UAx4{ z!)um@gsEkxUfbI}Tn0H&vuhdka)g}RGMyxH&I*l6s^uc%td{^(uI-en zT6M47r`M#HvuZMxQ(p>_538*cX{V14o7!%(Z$&bRwbbg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