WebHost: cleanup generate and hopefully fix SQL concurrency problems

This commit is contained in:
Fabian Dill
2022-07-07 01:38:50 +02:00
committed by Fabian Dill
parent 449bc93307
commit 74b19dc1f5
2 changed files with 21 additions and 21 deletions

View File

@@ -154,8 +154,10 @@ def autogen(config: dict):
while 1:
time.sleep(0.1)
with db_session:
# for update locks the database row(s) during transaction, preventing writes from elsewhere
to_start = select(
generation for generation in Generation if generation.state == STATE_QUEUED)
generation for generation in Generation
if generation.state == STATE_QUEUED).for_update()
for generation in to_start:
launch_generator(generator_pool, generation)
except AlreadyRunningException: