only run cleanup if folders exist

This commit is contained in:
j 2025-12-23 22:14:22 +01:00
commit bc4e715ce4

View file

@ -150,14 +150,17 @@ def extract_clip(public_id, in_, out, resolution, format, track=None):
def clear_cache(days=60): def clear_cache(days=60):
import subprocess import subprocess
path = os.path.join(settings.MEDIA_ROOT, 'media') path = os.path.join(settings.MEDIA_ROOT, 'media')
cmd = ['find', path, '-iregex', '.*/frames/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';'] if os.path.exists(path):
subprocess.check_output(cmd) cmd = ['find', path, '-iregex', '.*/frames/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';']
path = os.path.join(settings.MEDIA_ROOT, 'items') subprocess.check_output(cmd)
cmd = ['find', path, '-iregex', '.*/cache/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';'] if os.path.exists(path):
subprocess.check_output(cmd) path = os.path.join(settings.MEDIA_ROOT, 'items')
cmd = ['find', path, '-iregex', '.*/cache/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';']
subprocess.check_output(cmd)
path = settings.MEDIA_ROOT path = settings.MEDIA_ROOT
cmd = ['find', path, '-type', 'd', '-size', '0', '-prune', '-exec', 'rmdir', '{}', ';'] if os.path.exists(path):
subprocess.check_output(cmd) cmd = ['find', path, '-type', 'd', '-size', '0', '-prune', '-exec', 'rmdir', '{}', ';']
subprocess.check_output(cmd)
@app.task(ignore_results=True, queue='default') @app.task(ignore_results=True, queue='default')