[enh] broadcast new job creation

This commit is contained in:
Laurent Peuch 2018-07-15 06:23:35 +02:00
parent 5461bd996d
commit 7a201a530e
2 changed files with 14 additions and 1 deletions

13
run.py
View file

@ -68,7 +68,7 @@ async def initialize_app_list():
) )
print(f"Schedule a new build for {app_id}") print(f"Schedule a new build for {app_id}")
Job.create( job = Job.create(
name=f"{app_id} stable", name=f"{app_id} stable",
url_or_path=repo.url, url_or_path=repo.url,
target_revision=app_data["git"]["revision"], target_revision=app_data["git"]["revision"],
@ -76,6 +76,12 @@ async def initialize_app_list():
state="scheduled", state="scheduled",
) )
print(job)
await broadcast({
"action": "new_job",
"data": model_to_dict(job),
}, "jobs")
async def jobs_dispatcher(): async def jobs_dispatcher():
if Worker.select().count() == 0: if Worker.select().count() == 0:
@ -249,6 +255,11 @@ async def api_new_job(request):
print(f"Request to add new job '{job.name}' {job}") print(f"Request to add new job '{job.name}' {job}")
await broadcast({
"action": "new_job",
"data": model_to_dict(job),
}, "jobs")
return response.text("ok") return response.text("ok")

View file

@ -59,6 +59,8 @@
return; return;
} }
} }
} else if (action == "new_job") {
app.jobs.splice(0, 0, data);
} }
}; };
})() })()