[enh] boardcasts logs

This commit is contained in:
Laurent Peuch 2018-07-15 03:40:23 +02:00
parent f0c5e9c597
commit 5b51fbfef6
2 changed files with 30 additions and 11 deletions

View file

@ -26,6 +26,8 @@ class Job(peewee.Model):
('failure', 'Failure'), ('failure', 'Failure'),
), default="scheduled") ), default="scheduled")
log = peewee.TextField(default="")
created_time = peewee.DateTimeField(constraints=[peewee.SQL("DEFAULT (datetime('now'))")]) created_time = peewee.DateTimeField(constraints=[peewee.SQL("DEFAULT (datetime('now'))")])
started_time = peewee.DateTimeField(null=True) started_time = peewee.DateTimeField(null=True)
end_time = peewee.DateTimeField(null=True) end_time = peewee.DateTimeField(null=True)

25
run.py
View file

@ -115,9 +115,9 @@ async def jobs_dispatcher():
async def run_job(worker, job): async def run_job(worker, job):
await broadcast({ await broadcast({
"action": "job", "action": "update_job",
"data": model_to_dict(job), "data": model_to_dict(job),
}, "jobs") }, ["jobs", f"job-{job.id}"])
# fake stupid command, whould run CI instead # fake stupid command, whould run CI instead
print(f"Starting job {job.name}...") print(f"Starting job {job.name}...")
@ -128,6 +128,19 @@ async def run_job(worker, job):
while not command.stdout.at_eof(): while not command.stdout.at_eof():
data = await command.stdout.readline() data = await command.stdout.readline()
line = data.decode().rstrip() line = data.decode().rstrip()
job.log += data.decode()
# XXX seems to be okay performance wise but that's probably going to be
# a bottleneck at some point :/
# theoritically jobs are going to have slow output
job.save()
await broadcast({
"action": "update_job",
"id": job.id,
"data": model_to_dict(job),
}, ["jobs", f"job-{job.id}"])
print(f">> {line}") print(f">> {line}")
# XXX stupid crap to stimulate long jobs # XXX stupid crap to stimulate long jobs
@ -147,10 +160,14 @@ async def run_job(worker, job):
"action": "update_job", "action": "update_job",
"id": job.id, "id": job.id,
"data": model_to_dict(job), "data": model_to_dict(job),
}, "jobs") }, ["jobs", f"job-{job.id}"])
async def broadcast(message, channel): async def broadcast(message, channels):
if not isinstance(channels, (list, tuple)):
channels = [channels]
for channel in channels:
ws_list = subscriptions[channel] ws_list = subscriptions[channel]
dead_ws = [] dead_ws = []