• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EsupPortail / Esup-Pod / 17650665259

11 Sep 2025 04:16PM UTC coverage: 70.657% (+0.07%) from 70.584%
17650665259

Pull #1353

github

web-flow
Merge 29bc9f07b into dd08c8e65
Pull Request #1353: Multiples instances de pods dans l'environnement Docker

25 of 30 new or added lines in 6 files covered. (83.33%)

4 existing lines in 2 files now uncovered.

12081 of 17098 relevant lines covered (70.66%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.28
/pod/video_encode_transcript/transcripting_tasks.py
1
"""Esup-Pod transcripting tasks."""
2

3
# pip3 install celery==5.4.0
4
# pip3 install webvtt-py
5
# pip3 install redis==4.5.4
6
from celery import Celery
1✔
7
from tempfile import NamedTemporaryFile
1✔
8
import logging
1✔
9
import os
1✔
10
import requests
1✔
11

12
# call local settings directly
13
# no need to load pod application to send statement
14
try:
1✔
15
    from ..custom import settings_local
1✔
16
except ImportError:
×
17
    from .. import settings as settings_local
×
18

19
logger = logging.getLogger(__name__)
1✔
20

21
EMAIL_HOST = getattr(settings_local, "EMAIL_HOST", "")
1✔
22
DEFAULT_FROM_EMAIL = getattr(settings_local, "DEFAULT_FROM_EMAIL", "")
1✔
23
ADMINS = getattr(settings_local, "ADMINS", ())
1✔
24
DEBUG = getattr(settings_local, "DEBUG", True)
1✔
25
INSTANCE = getattr(settings_local, "INSTANCE", None)
1✔
26
TEST_REMOTE_ENCODE = getattr(settings_local, "TEST_REMOTE_ENCODE", False)
1✔
27

28
admins_email = [ad[1] for ad in ADMINS]
1✔
29

30
if DEBUG:
1✔
31
    logger.setLevel(logging.DEBUG)
1✔
32

33
smtp_handler = logging.handlers.SMTPHandler(
1✔
34
    mailhost=EMAIL_HOST,
35
    fromaddr=DEFAULT_FROM_EMAIL,
36
    toaddrs=admins_email,
37
    subject="[POD TRANSCRIPT] Transcripting Log Mail",
38
)
39
if not TEST_REMOTE_ENCODE:
1✔
40
    logger.addHandler(smtp_handler)
×
41

42
POD_API_URL = getattr(settings_local, "POD_API_URL", "")
1✔
43
POD_API_TOKEN = getattr(settings_local, "POD_API_TOKEN", "")
1✔
44

45
ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
1✔
46
    settings_local, "ENCODING_TRANSCODING_CELERY_BROKER_URL", ""
47
)
48

49
transcripting_app = Celery(
1✔
50
    "transcripting_tasks", broker=ENCODING_TRANSCODING_CELERY_BROKER_URL
51
)
52
transcripting_app.conf.task_routes = {
1✔
53
    "pod.video_encode_transcript.transcripting_tasks.*": {"queue": "transcripting"}
54
}
55
if INSTANCE:
1✔
NEW
56
    transcripting_app.conf.broker_transport_options = {"global_keyprefix": INSTANCE}
×
57
transcripting_app.autodiscover_tasks(packages=None, related_name="", force=False)
1✔
58

59

60
# celery \
61
# -A pod.video_encode_transcript.transcripting_tasks worker \
62
# -l INFO -Q transcripting
63
@transcripting_app.task(bind=True)
1✔
64
def start_transcripting_task(self, video_id, mp3filepath, duration, lang):
1✔
65
    """Start the transcripting of the video."""
66
    from .transcript_model import start_transcripting
×
67
    from ..main.settings import MEDIA_ROOT
×
68

69
    print("Start the transcripting of the video %s" % video_id)
×
70
    print(video_id, mp3filepath, duration, lang)
×
71
    msg, text_webvtt = start_transcripting(mp3filepath, duration, lang)
×
72
    print("End of the transcripting of the video")
×
73
    media_temp_dir = os.path.join(MEDIA_ROOT, "temp")
×
74
    if not os.path.exists(media_temp_dir):
×
75
        os.mkdir(media_temp_dir)
×
76
    temp_vtt_file = NamedTemporaryFile(dir=media_temp_dir, delete=False, suffix=".vtt")
×
77
    text_webvtt.save(temp_vtt_file.name)
×
78
    print("End of the transcoding of the video")
×
79
    Headers = {"Authorization": "Token %s" % POD_API_TOKEN}
×
80
    url = POD_API_URL.strip("/") + "/store_remote_transcripted_video/?id=%s" % video_id
×
81
    data = {"video_id": video_id, "msg": msg, "temp_vtt_file": temp_vtt_file.name}
×
82
    msg = "Task id : %s\n" % self.request.id
×
83
    try:
×
84
        response = requests.post(url, json=data, headers=Headers)
×
85
        if response.status_code != 200:
×
86
            msg += "Calling store remote transcoding error: {} {}".format(
×
87
                response.status_code, response.reason
88
            )
89
            logger.error(msg + "\n" + str(response.content))
×
90
        else:
91
            logger.info(msg + "Call importing transcript task ok")
×
92
    except (
×
93
        requests.exceptions.HTTPError,
94
        requests.exceptions.ConnectionError,
95
        requests.exceptions.InvalidURL,
96
        requests.exceptions.Timeout,
97
    ) as exception:
98
        msg += "Exception: {}".format(type(exception).__name__)
×
99
        msg += "\nException message: {}".format(exception)
×
100
        logger.error(msg)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc