mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-10 09:28:53 -05:00
disable signal refactoring
This commit is contained in:
parent
a833b606f1
commit
d940cad56b
@ -16,15 +16,24 @@ from django.core.files import File
|
|||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
|
||||||
from cms import celery_app
|
from cms import celery_app
|
||||||
|
|
||||||
from . import helpers, models
|
from . import helpers, models
|
||||||
from .models import Encoding
|
|
||||||
from .helpers import mask_ip
|
from .helpers import mask_ip
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def disable_signal(signal, receiver, sender):
|
||||||
|
signal.disconnect(receiver, sender=sender)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
signal.connect(receiver, sender=sender)
|
||||||
|
|
||||||
|
|
||||||
def get_user_or_session(request):
|
def get_user_or_session(request):
|
||||||
"""Return a dictionary with user info
|
"""Return a dictionary with user info
|
||||||
@ -415,36 +424,38 @@ def copy_video(original_media, copy_encodings=True, title_suffix="(Trimmed)"):
|
|||||||
New Media object
|
New Media object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open(original_media.media_file.path, "rb") as f:
|
with disable_signal(post_save, models.media_save, models.Media):
|
||||||
myfile = File(f)
|
with open(original_media.media_file.path, "rb") as f:
|
||||||
new_media = models.Media.objects.create(
|
myfile = File(f)
|
||||||
media_file=myfile,
|
new_media = models.Media.objects.create(
|
||||||
title=f"{original_media.title} {title_suffix}",
|
media_file=myfile,
|
||||||
description=original_media.description,
|
title=f"{original_media.title} {title_suffix}",
|
||||||
user=original_media.user,
|
description=original_media.description,
|
||||||
media_type="video",
|
user=original_media.user,
|
||||||
enable_comments=original_media.enable_comments,
|
media_type="video",
|
||||||
allow_download=original_media.allow_download,
|
enable_comments=original_media.enable_comments,
|
||||||
state=original_media.state,
|
allow_download=original_media.allow_download,
|
||||||
is_reviewed=original_media.is_reviewed,
|
state=original_media.state,
|
||||||
add_date=timezone.now()
|
is_reviewed=original_media.is_reviewed,
|
||||||
)
|
add_date=timezone.now()
|
||||||
|
)
|
||||||
|
|
||||||
if copy_encodings:
|
if copy_encodings:
|
||||||
for encoding in original_media.encodings.filter(status="success", chunk=False):
|
for encoding in original_media.encodings.filter(status="success", chunk=False):
|
||||||
if encoding.media_file:
|
if encoding.media_file:
|
||||||
with open(encoding.media_file.path, "rb") as f:
|
with disable_signal(post_save, models.encoding_file_save, models.Encoding):
|
||||||
myfile = File(f)
|
with open(encoding.media_file.path, "rb") as f:
|
||||||
new_encoding = Encoding.objects.create(
|
myfile = File(f)
|
||||||
media_file=myfile,
|
new_encoding = models.Encoding.objects.create(
|
||||||
media=new_media,
|
media_file=myfile,
|
||||||
profile=encoding.profile,
|
media=new_media,
|
||||||
status="success",
|
profile=encoding.profile,
|
||||||
progress=100,
|
status="success",
|
||||||
chunk=False,
|
progress=100,
|
||||||
logs=f"Copied from encoding {encoding.id}"
|
chunk=False,
|
||||||
)
|
logs=f"Copied from encoding {encoding.id}"
|
||||||
new_encoding.save()
|
)
|
||||||
|
new_encoding.save()
|
||||||
|
|
||||||
# Copy categories and tags
|
# Copy categories and tags
|
||||||
for category in original_media.category.all():
|
for category in original_media.category.all():
|
||||||
|
|||||||
@ -84,6 +84,7 @@ ENCODE_EXTENSIONS_KEYS = [extension for extension, name in ENCODE_EXTENSIONS]
|
|||||||
ENCODE_RESOLUTIONS_KEYS = [resolution for resolution, name in ENCODE_RESOLUTIONS]
|
ENCODE_RESOLUTIONS_KEYS = [resolution for resolution, name in ENCODE_RESOLUTIONS]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_uid():
|
def generate_uid():
|
||||||
return get_random_string(length=16)
|
return get_random_string(length=16)
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,6 @@ 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.models.signals import post_save
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
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
|
||||||
@ -48,8 +46,7 @@ from .models import (
|
|||||||
Rating,
|
Rating,
|
||||||
Tag,
|
Tag,
|
||||||
VideoChapterData,
|
VideoChapterData,
|
||||||
VideoTrimRequest,
|
VideoTrimRequest
|
||||||
media_save
|
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = get_task_logger(__name__)
|
logger = get_task_logger(__name__)
|
||||||
@ -63,14 +60,6 @@ ERRORS_LIST = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def disable_signal(signal, receiver, sender):
|
|
||||||
signal.disconnect(receiver, sender=sender)
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
signal.connect(receiver, sender=sender)
|
|
||||||
|
|
||||||
|
|
||||||
@task(name="chunkize_media", bind=True, queue="short_tasks", soft_time_limit=60 * 30 * 4)
|
@task(name="chunkize_media", bind=True, queue="short_tasks", soft_time_limit=60 * 30 * 4)
|
||||||
def chunkize_media(self, friendly_token, profiles, force=True):
|
def chunkize_media(self, friendly_token, profiles, force=True):
|
||||||
@ -854,7 +843,7 @@ def produce_video_chapters(chapter_id):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@task(name="video_trim_task", bind=True, queue="short_tasks")
|
@task(name="video_trim_task", bind=True, queue="short_tasks", soft_time_limit=600)
|
||||||
def video_trim_task(self, trim_request_id):
|
def video_trim_task(self, trim_request_id):
|
||||||
# SOS: if at some point we move from ffmpeg copy, then this need be changed
|
# SOS: if at some point we move from ffmpeg copy, then this need be changed
|
||||||
# to long_tasks
|
# to long_tasks
|
||||||
@ -891,8 +880,7 @@ def video_trim_task(self, trim_request_id):
|
|||||||
if proceed_with_single_file:
|
if proceed_with_single_file:
|
||||||
|
|
||||||
if trim_request.video_action == "save_new" or trim_request.video_action == "create_segments" and len(timestamps_encodings) == 1:
|
if trim_request.video_action == "save_new" or trim_request.video_action == "create_segments" and len(timestamps_encodings) == 1:
|
||||||
with disable_signal(post_save, media_save, Media):
|
new_media = copy_video(original_media, copy_encodings=True)
|
||||||
new_media = copy_video(original_media, copy_encodings=True)
|
|
||||||
|
|
||||||
target_media = new_media
|
target_media = new_media
|
||||||
trim_request.media = new_media
|
trim_request.media = new_media
|
||||||
@ -924,8 +912,7 @@ def video_trim_task(self, trim_request_id):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
for i, timestamp in enumerate(timestamps_encodings, start=1):
|
for i, timestamp in enumerate(timestamps_encodings, start=1):
|
||||||
with disable_signal(post_save, media_save, Media):
|
new_media = copy_video(original_media, title_suffix=f"(Trimmed) {i}", copy_encodings=True)
|
||||||
new_media = copy_video(original_media, title_suffix=f"(Trimmed) {i}", copy_encodings=True)
|
|
||||||
|
|
||||||
original_trim_result = trim_video_method(new_media.media_file.path, [timestamp])
|
original_trim_result = trim_video_method(new_media.media_file.path, [timestamp])
|
||||||
encodings = new_media.encodings.filter(status="success", profile__extension='mp4', chunk=False)
|
encodings = new_media.encodings.filter(status="success", profile__extension='mp4', chunk=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user