• 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

39.71
/pod/video_encode_transcript/encoding_tasks.py
1
"""Esup-Pod encoding 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
import logging
1✔
8
import requests
1✔
9

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

17
EMAIL_HOST = getattr(settings_local, "EMAIL_HOST", "")
1✔
18
DEFAULT_FROM_EMAIL = getattr(settings_local, "DEFAULT_FROM_EMAIL", "")
1✔
19
ADMINS = getattr(settings_local, "ADMINS", ())
1✔
20
DEBUG = getattr(settings_local, "DEBUG", True)
1✔
21
INSTANCE = getattr(settings_local, "INSTANCE", None)
1✔
22
TEST_REMOTE_ENCODE = getattr(settings_local, "TEST_REMOTE_ENCODE", False)
1✔
23

24
admins_email = [ad[1] for ad in ADMINS]
1✔
25

26
logger = logging.getLogger(__name__)
1✔
27
if DEBUG:
1✔
28
    logger.setLevel(logging.DEBUG)
1✔
29

30
smtp_handler = logging.handlers.SMTPHandler(
1✔
31
    mailhost=EMAIL_HOST,
32
    fromaddr=DEFAULT_FROM_EMAIL,
33
    toaddrs=admins_email,
34
    subject="[POD ENCODING] Encoding Log Mail",
35
)
36
if not TEST_REMOTE_ENCODE:
1✔
37
    logger.addHandler(smtp_handler)
×
38

39
ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
1✔
40
    settings_local, "ENCODING_TRANSCODING_CELERY_BROKER_URL", ""
41
)
42
POD_API_URL = getattr(settings_local, "POD_API_URL", "")
1✔
43
POD_API_TOKEN = getattr(settings_local, "POD_API_TOKEN", "")
1✔
44
encoding_app = Celery("encoding_tasks", broker=ENCODING_TRANSCODING_CELERY_BROKER_URL)
1✔
45
encoding_app.conf.task_routes = {
1✔
46
    "pod.video_encode_transcript.encoding_tasks.*": {"queue": "encoding"}
47
}
48
if INSTANCE:
1✔
NEW
49
    encoding_app.conf.broker_transport_options = {"global_keyprefix": INSTANCE}
×
50

51

52
# celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding
53
@encoding_app.task(bind=True)
1✔
54
def start_encoding_task(
1✔
55
    self, video_id, video_path, cut_start, cut_end, json_dressing, dressing_input
56
):
57
    """Start the encoding of the video."""
58
    print("Start the encoding of the video")
×
59
    from .Encoding_video import Encoding_video
×
60

61
    print(video_id, video_path, cut_start, cut_end)
×
62
    encoding_video = Encoding_video(
×
63
        video_id, video_path, cut_start, cut_end, json_dressing, dressing_input
64
    )
65
    encoding_video.start_encode()
×
66
    print("End of the encoding of the video")
×
67
    Headers = {"Authorization": "Token %s" % POD_API_TOKEN}
×
68
    url = POD_API_URL.strip("/") + "/store_remote_encoded_video/?id=%s" % video_id
×
69
    data = {
×
70
        "start": encoding_video.start,
71
        "video_id": video_id,
72
        "video_path": video_path,
73
        "cut_start": cut_start,
74
        "cut_end": cut_end,
75
        "stop": encoding_video.stop,
76
        "json_dressing": json_dressing,
77
        "dressing_input": dressing_input,
78
    }
79
    msg = "Task id : %s\n" % self.request.id
×
80
    try:
×
81
        response = requests.post(url, json=data, headers=Headers)
×
82
        if response.status_code != 200:
×
83
            msg += "Calling store remote encoding error: {} {}".format(
×
84
                response.status_code, response.reason
85
            )
86
            logger.error(msg + "\n" + str(response.content))
×
87
        else:
88
            logger.info(msg + "Call importing encoding task ok")
×
89
    except (
×
90
        requests.exceptions.HTTPError,
91
        requests.exceptions.ConnectionError,
92
        requests.exceptions.InvalidURL,
93
        requests.exceptions.Timeout,
94
    ) as exception:
95
        msg += "Exception: {}".format(type(exception).__name__)
×
96
        msg += "\nException message: {}".format(exception)
×
97
        logger.error(msg)
×
98

99

100
@encoding_app.task
1✔
101
def start_studio_task(recording_id, video_output, videos, subtime, presenter):
1✔
102
    from .encoding_studio import start_encode_video_studio
×
103

104
    print("Start the encoding studio of the video")
×
105
    msg = start_encode_video_studio(video_output, videos, subtime, presenter)
×
106
    print("End of the encoding studio of the video")
×
107
    Headers = {"Authorization": "Token %s" % POD_API_TOKEN}
×
108
    url = (
×
109
        POD_API_URL.strip("/")
110
        + "/store_remote_encoded_video_studio/?recording_id=%s" % recording_id
111
    )
112
    data = {
×
113
        "video_output": video_output,
114
        "msg": msg,
115
    }
116
    try:
×
117
        response = requests.post(url, json=data, headers=Headers)
×
118
        if response.status_code != 200:
×
119
            msg = "Calling store remote encoding studio error: {} {}".format(
×
120
                response.status_code, response.reason
121
            )
122
            logger.error(msg + "\n" + str(response.content))
×
123
        else:
124
            logger.info("Call importing encoded studio task ok")
×
125
    except (
×
126
        requests.exceptions.HTTPError,
127
        requests.exceptions.ConnectionError,
128
        requests.exceptions.InvalidURL,
129
        requests.exceptions.Timeout,
130
    ) as exception:
131
        msg = "Exception: {}".format(type(exception).__name__)
×
132
        msg += "\nException message: {}".format(exception)
×
133
        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