mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-06 15:38:53 -05:00
try
This commit is contained in:
parent
cb6004ce15
commit
621d2bfcec
@ -649,6 +649,9 @@ class Media(models.Model):
|
|||||||
from . import tasks
|
from . import tasks
|
||||||
tasks.create_hls.delay(self.friendly_token)
|
tasks.create_hls.delay(self.friendly_token)
|
||||||
|
|
||||||
|
need_to_run_post_trim_action = False
|
||||||
|
if need_to_run_post_trim_action:
|
||||||
|
tasks.post_trim_action.delay(self.friendly_token)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_encoding_status(self):
|
def set_encoding_status(self):
|
||||||
|
|||||||
@ -17,7 +17,7 @@ from django.conf import settings
|
|||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.db import DatabaseError
|
||||||
from actions.models import USER_MEDIA_ACTIONS, MediaAction
|
from actions.models import USER_MEDIA_ACTIONS, MediaAction
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
|
||||||
@ -350,18 +350,28 @@ def encode_media(
|
|||||||
percent = duration * 100 / media.duration
|
percent = duration * 100 / media.duration
|
||||||
if n_times % 60 == 0:
|
if n_times % 60 == 0:
|
||||||
encoding.progress = percent
|
encoding.progress = percent
|
||||||
try:
|
|
||||||
encoding.save(update_fields=["progress", "update_date"])
|
encoding.save(update_fields=["progress", "update_date"])
|
||||||
logger.info("Saved {0}".format(round(percent, 2)))
|
logger.info("Saved {0}".format(round(percent, 2)))
|
||||||
except Exception as e:
|
|
||||||
raise
|
|
||||||
n_times += 1
|
n_times += 1
|
||||||
|
except DatabaseError as e:
|
||||||
|
print(e, 'XA'*100)
|
||||||
|
kill_ffmpeg_process(encoding.temp_file)
|
||||||
|
kill_ffmpeg_process(encoding.chunk_file_path)
|
||||||
|
return False
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
except VideoEncodingError:
|
except VideoEncodingError:
|
||||||
# ffmpeg error, or ffmpeg was killed
|
# ffmpeg error, or ffmpeg was killed
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if isinstance(e, DatabaseError):
|
||||||
|
print(e, 'BA'*100)
|
||||||
|
kill_ffmpeg_process(encoding.temp_file)
|
||||||
|
kill_ffmpeg_process(encoding.chunk_file_path)
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# output is empty, fail message is on the exception
|
# output is empty, fail message is on the exception
|
||||||
output = e.message
|
output = e.message
|
||||||
@ -967,14 +977,14 @@ def video_trim_task(self, trim_request_id):
|
|||||||
if deleted_encodings:
|
if deleted_encodings:
|
||||||
# give the chance to run encodings for encodings that didnt make it
|
# give the chance to run encodings for encodings that didnt make it
|
||||||
target_media.encode(force=False)
|
target_media.encode(force=False)
|
||||||
|
trim_request_status = "running"
|
||||||
# TODO: find way to call post_trim_action only after this has finished...
|
# TODO: find way to call post_trim_action only after this has finished...
|
||||||
else:
|
else:
|
||||||
post_trim_action.delay(target_media.friendly_token)
|
post_trim_action.delay(target_media.friendly_token)
|
||||||
|
trim_request_status = "success"
|
||||||
|
|
||||||
trim_request.status = "success"
|
trim_request.status = trim_request_status
|
||||||
trim_request.save(update_fields=["status"])
|
trim_request.save(update_fields=["status"])
|
||||||
logger.info(f"Successfully processed video trim request {trim_request_id} for media {target_media.friendly_token}")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for i, timestamp in enumerate(timestamps_encodings, start=1):
|
for i, timestamp in enumerate(timestamps_encodings, start=1):
|
||||||
# copy the original file for each of the segments. This could be optimized to avoid the overhead but
|
# copy the original file for each of the segments. This could be optimized to avoid the overhead but
|
||||||
@ -994,11 +1004,13 @@ def video_trim_task(self, trim_request_id):
|
|||||||
if deleted_encodings:
|
if deleted_encodings:
|
||||||
# give the chance to run encodings for encodings that didnt make it
|
# give the chance to run encodings for encodings that didnt make it
|
||||||
target_media.encode(force=False)
|
target_media.encode(force=False)
|
||||||
|
trim_request_status = "running"
|
||||||
# TODO: find way to call post_trim_action only after this has finished...
|
# TODO: find way to call post_trim_action only after this has finished...
|
||||||
else:
|
else:
|
||||||
post_trim_action.delay(target_media.friendly_token)
|
post_trim_action.delay(target_media.friendly_token)
|
||||||
|
trim_request_status = "success"
|
||||||
|
|
||||||
trim_request.status = "success"
|
trim_request.status = trim_request_status
|
||||||
trim_request.save(update_fields=["status"])
|
trim_request.save(update_fields=["status"])
|
||||||
logger.info(f"Successfully processed video trim request {trim_request_id} for media {original_media.friendly_token}")
|
logger.info(f"Successfully processed video trim request {trim_request_id} for media {original_media.friendly_token}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user