From d2da5ae581925b98d5b28a3c278d71f68618a171 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 24 Jan 2025 20:54:25 +0530 Subject: [PATCH] add tasks queue --- tasks.py | 9 +++++++++ views.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/tasks.py b/tasks.py index b0ba8d4..88d887d 100644 --- a/tasks.py +++ b/tasks.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from datetime import datetime import logging from app.celery import app @@ -24,6 +25,11 @@ def transcribe(**kwargs): join_sentences = getattr(settings, "TRANSCRIBE_JOIN", False) model = getattr(settings, "TRANSCRIBE_MODEL", "small") translate = getattr(settings, "TRANSCRIBE_TRANSLATE", "") + task, created = Task.objects.get_or_create(item=item) + task.user = user + task.status = 'transcribing' + task.started = datetime.now() + task.save() extract_subtitles( item, user, @@ -33,3 +39,6 @@ def transcribe(**kwargs): join_sentences=join_sentences, model=model ) + task.ended = datetime.now() + task.status = 'finished' + task.save() diff --git a/views.py b/views.py index 90d2379..c2882d7 100644 --- a/views.py +++ b/views.py @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- +from datetime import datetime + from oxdjango.decorators import login_required_json from oxdjango.shortcuts import render_to_json_response, get_object_or_404_json, json_response from item.models import Item from oxdjango.api import actions +from taskqueue.models import Task from user.models import has_capability from . import tasks @@ -24,6 +27,10 @@ def transcribeAudio(request, data): response = json_response() item = get_object_or_404_json(Item, public_id=data["item"]) if has_capability(request.user, 'canTranscribeAudio') and item.editable(request.user): + task, created = Task.objects.get_or_create(item=item) + task.user = request.user + task.status = 'transcribing' + task.save() t = tasks.transcribe.delay(item=data["item"], user=request.user.username) response["data"]["taskId"] = t.task_id else: