Skip to content

Commit

Permalink
create command to launch celery task
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitloup committed Jun 30, 2023
1 parent bfc9498 commit 83465db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 10 additions & 3 deletions pod/video_encode_transcript/importing_transcript_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from celery import Celery
from .. import settings
import logging
import io
import webvtt
logger = logging.getLogger(__name__)

ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
Expand All @@ -20,12 +22,17 @@
}


# celery -A pod.video_encode_transcript.importing_tasks worker -l INFO -Q importing
# celery \
# -A pod.video_encode_transcript.importing_transcript_tasks worker \
# -l INFO -Q importing_transcript
@importing_transcript_app.task
def start_importing_transcript_task(video_id, msg, webvtt):
def start_importing_transcript_task(video_id, msg, textwebvtt):
"""Start the encoding of the video."""
print("Start the importing transcript of the video ID : %s" % video_id)
from pod.video.models import Video
from .transcript import save_vtt_and_notify
video_to_encode = Video.objects.get(id=video_id)
save_vtt_and_notify(video_to_encode, msg, webvtt)
textwebvtt = "WEBVTT\\n\\n" + textwebvtt
f = io.StringIO(textwebvtt)
new_vtt = webvtt.read_buffer(f)
save_vtt_and_notify(video_to_encode, msg, new_vtt)
2 changes: 1 addition & 1 deletion pod/video_encode_transcript/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main_threaded_transcript(video_to_encode_id):
else:
mp3filepath = mp3file.path
if USE_DISTANT_ENCODING_TRANSCODING:
start_transcripting_task(
start_transcripting_task.delay(
video_to_encode.id,
mp3filepath,
video_to_encode.duration,
Expand Down
6 changes: 4 additions & 2 deletions pod/video_encode_transcript/transcripting_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
}


# celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding
# celery \
# -A pod.video_encode_transcript.transcripting_tasks worker \
# -l INFO -Q transcripting
@transcripting_app.task
def start_transcripting_task(video_id, mp3filepath, duration, lang):
"""Start the encoding of the video."""
print("Start the transcripting of the video %s" % video_id)
msg, webvtt = start_transcripting(mp3filepath, duration, lang)
print("End of the transcripting of the video")
start_importing_transcript_task.delay(video_id, msg, webvtt)
start_importing_transcript_task.delay(video_id, msg, str(webvtt))

0 comments on commit 83465db

Please sign in to comment.