diff --git a/files/methods.py b/files/methods.py index 6d5ca93f..4e984dc5 100644 --- a/files/methods.py +++ b/files/methods.py @@ -423,7 +423,6 @@ def copy_video(original_media, copy_encodings=True, title_suffix="(Trimmed)"): Returns: New Media object """ - from .tasks import update_encoding_size with open(original_media.media_file.path, "rb") as f: myfile = File(f) diff --git a/files/models.py b/files/models.py index 091243e1..3dbe60e8 100644 --- a/files/models.py +++ b/files/models.py @@ -644,8 +644,9 @@ class Media(models.Model): if encoding and encoding.status == "success" and encoding.profile.codec == "h264" and action == "add" and not encoding.chunk: from . import tasks - + logger.info('ti simbainei edw') tasks.create_hls(self.friendly_token) + print('ti simbainei edw2') return True @@ -1221,17 +1222,17 @@ class Encoding(models.Model): super(Encoding, self).save(*args, **kwargs) - def update_size(self): - """Update the size of the encoding file""" - if self.media_file: - cmd = ["stat", "-c", "%s", self.media_file.path] - stdout = helpers.run_command(cmd).get("out") - if stdout: - size = int(stdout.strip()) - self.size = helpers.show_file_size(size) - self.save(update_fields=["size"]) - return True - return False + def update_size_without_save(self): + """Update the size of an encoding without saving to avoid calling signals""" + if self.media_file: + cmd = ["stat", "-c", "%s", self.media_file.path] + stdout = helpers.run_command(cmd).get("out") + if stdout: + size = int(stdout.strip()) + size = helpers.show_file_size(size) + Encoding.objects.filter(pk=self.pk).update(size=size) + return True + return False def set_progress(self, progress, commit=True): if isinstance(progress, int): diff --git a/files/tasks.py b/files/tasks.py index d2a5e768..f56c01c9 100644 --- a/files/tasks.py +++ b/files/tasks.py @@ -810,14 +810,12 @@ def remove_media_file(media_file=None): @task(name="update_encoding_size", queue="short_tasks") def update_encoding_size(encoding_id): - """Update the size of an encoding""" - try: - encoding = Encoding.objects.get(id=encoding_id) - encoding.update_size() + """Update the size of an encoding without saving to avoid calling signals""" + encoding = Encoding.objects.filter(id=encoding_id).first() + if encoding: + encoding.update_size_without_save() return True - except Encoding.DoesNotExist: - logger.info(f"Encoding with ID {encoding_id} not found") - return False + return False @task(name="produce_video_chapters", queue="short_tasks")