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

EsupPortail / Esup-Pod / 9664421460

25 Jun 2024 02:31PM UTC coverage: 70.938%. First build
9664421460

Pull #1139

github

web-flow
Merge 0834a594a into 46941e1c4
Pull Request #1139: [WIP] Ptitloup/remote encoding fix

3 of 16 new or added lines in 3 files covered. (18.75%)

12031 of 16960 relevant lines covered (70.94%)

0.71 hits per line

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

38.46
/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
TEST_REMOTE_ENCODE = getattr(settings_local, "TEST_REMOTE_ENCODE", False)
1✔
22

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

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

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

38
ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
1✔
39
    settings_local, "ENCODING_TRANSCODING_CELERY_BROKER_URL", ""
40
)
41
POD_API_URL = getattr(settings_local, "POD_API_URL", "")
1✔
42
POD_API_TOKEN = getattr(settings_local, "POD_API_TOKEN", "")
1✔
43
encoding_app = Celery("encoding_tasks", broker=ENCODING_TRANSCODING_CELERY_BROKER_URL)
1✔
44
encoding_app.conf.task_routes = {
1✔
45
    "pod.video_encode_transcript.encoding_tasks.*": {"queue": "encoding"}
46
}
47

48

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

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

96

97
@encoding_app.task
1✔
98
def start_studio_task(recording_id, video_output, videos, subtime, presenter):
1✔
99
    from .encoding_studio import start_encode_video_studio
×
100

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

© 2026 Coveralls, Inc