mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-23 13:36:35 +00:00
Add explicit transactions for certain tasks
This commit is contained in:
parent
ed3c7c6e9d
commit
58472f7785
@ -17,6 +17,7 @@ from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.utils import timezone
|
||||
from django.db.tansaction import atomic
|
||||
from django.db.utils import IntegrityError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from background_task import background
|
||||
@ -179,6 +180,7 @@ def cleanup_removed_media(source, videos):
|
||||
|
||||
|
||||
@background(schedule=300, remove_existing_tasks=True)
|
||||
@atomic(durable=True)
|
||||
def index_source_task(source_id):
|
||||
'''
|
||||
Indexes media available from a Source object.
|
||||
@ -221,6 +223,7 @@ def index_source_task(source_id):
|
||||
if published_dt is not None:
|
||||
media.published = published_dt
|
||||
try:
|
||||
with atomic():
|
||||
media.save()
|
||||
log.debug(f'Indexed media: {source} / {media}')
|
||||
# log the new media instances
|
||||
@ -611,6 +614,7 @@ def save_all_media_for_source(source_id):
|
||||
|
||||
# Trigger the post_save signal for each media item linked to this source as various
|
||||
# flags may need to be recalculated
|
||||
with atomic():
|
||||
for media in mqs:
|
||||
if media.uuid not in already_saved:
|
||||
media.save()
|
||||
@ -626,6 +630,7 @@ def rename_media(media_id):
|
||||
|
||||
|
||||
@background(schedule=300, remove_existing_tasks=True)
|
||||
@atomic(durable=True)
|
||||
def rename_all_media_for_source(source_id):
|
||||
try:
|
||||
source = Source.objects.get(pk=source_id)
|
||||
@ -653,6 +658,7 @@ def rename_all_media_for_source(source_id):
|
||||
downloaded=True,
|
||||
)
|
||||
for media in mqs:
|
||||
with atomic():
|
||||
media.rename_files()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user