add tasks queue
This commit is contained in:
parent
41e256be5d
commit
d2da5ae581
2 changed files with 16 additions and 0 deletions
9
tasks.py
9
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()
|
||||
|
|
7
views.py
7
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:
|
||||
|
|
Loading…
Reference in a new issue