mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[mod] avoid infinite loop to prevent memleaks
This commit is contained in:
parent
7835ea8b47
commit
ed6d7cf1c7
1 changed files with 24 additions and 25 deletions
7
run.py
7
run.py
|
@ -343,18 +343,17 @@ async def launch_monthly_job(type):
|
||||||
await create_job(repo.name, repo.app_list, repo, job_command_last_part)
|
await create_job(repo.name, repo.app_list, repo, job_command_last_part)
|
||||||
|
|
||||||
|
|
||||||
|
@always_relaunch(sleep=3)
|
||||||
async def jobs_dispatcher():
|
async def jobs_dispatcher():
|
||||||
if Worker.select().count() == 0:
|
if Worker.select().count() == 0:
|
||||||
for i in range(1):
|
for i in range(1):
|
||||||
Worker.create(state="available")
|
Worker.create(state="available")
|
||||||
|
|
||||||
while True:
|
|
||||||
workers = Worker.select().where(Worker.state == "available")
|
workers = Worker.select().where(Worker.state == "available")
|
||||||
|
|
||||||
# no available workers, wait
|
# no available workers, wait
|
||||||
if workers.count() == 0:
|
if workers.count() == 0:
|
||||||
await asyncio.sleep(3)
|
return
|
||||||
continue
|
|
||||||
|
|
||||||
with db.atomic('IMMEDIATE'):
|
with db.atomic('IMMEDIATE'):
|
||||||
jobs = Job.select().where(Job.state == "scheduled")
|
jobs = Job.select().where(Job.state == "scheduled")
|
||||||
|
@ -362,7 +361,7 @@ async def jobs_dispatcher():
|
||||||
# no jobs to process, wait
|
# no jobs to process, wait
|
||||||
if jobs.count() == 0:
|
if jobs.count() == 0:
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
continue
|
return
|
||||||
|
|
||||||
for i in range(min(workers.count(), jobs.count())):
|
for i in range(min(workers.count(), jobs.count())):
|
||||||
job = jobs[i]
|
job = jobs[i]
|
||||||
|
|
Loading…
Add table
Reference in a new issue