Skip to content

Commit d2b859f

Browse files
committed
fix: Reduce the chance of a recording import race
1 parent 680509d commit d2b859f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bbblb/services/recording.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from functools import cached_property
77
import logging
88
from pathlib import Path
9+
import random
910
from secrets import token_hex
1011
import secrets
1112
import shutil
1213
import tarfile
14+
import time
1315
import typing
1416
import uuid
1517
import lxml.etree
@@ -193,7 +195,7 @@ async def run(self):
193195
await asyncio.sleep(self.poll_interval)
194196
if self.auto_import:
195197
await self.schedule_waiting()
196-
await self.cleanup()
198+
await self.cleanup()
197199
except asyncio.CancelledError:
198200
raise
199201
except BaseException:
@@ -204,7 +206,13 @@ async def run(self):
204206

205207
async def schedule_waiting(self):
206208
"""Pick up waiting tasks from inbox"""
209+
# Only pick up older files for which we are sure the regular
210+
# improt didn't work or was aborted.
211+
min_age = random.randint(60,120)
212+
207213
for file in self.inbox_dir.glob("*.tar"):
214+
if file.stat().st_mtime + min_age > time.time():
215+
continue
208216
self._schedule(RecordingImportTask(self, file.stem, file))
209217

210218
async def cleanup(self):

0 commit comments

Comments
 (0)