This commit is contained in:
parent
a2354c2ba7
commit
0aa8955b4a
@ -1,12 +1,13 @@
|
|||||||
from aiohttp import web
|
|
||||||
from typing import List
|
|
||||||
import shlex
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
import shlex
|
||||||
from zhurnal import log
|
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from aiohttp import web
|
||||||
|
|
||||||
|
from zhurnal import log
|
||||||
|
|
||||||
index_html = """
|
index_html = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -244,7 +245,7 @@ class Zhurnal(web.Application):
|
|||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
)
|
)
|
||||||
log.info("Running process {}: {}".format(process_name, command))
|
log.info(f"Running process {process_name}: {command}")
|
||||||
|
|
||||||
async def read_output(app, name, process, f):
|
async def read_output(app, name, process, f):
|
||||||
time_previous = 0
|
time_previous = 0
|
||||||
@ -259,42 +260,36 @@ class Zhurnal(web.Application):
|
|||||||
for client in app.clients:
|
for client in app.clients:
|
||||||
await client.send_str(
|
await client.send_str(
|
||||||
json.dumps(
|
json.dumps(
|
||||||
dict(
|
{
|
||||||
elapsed=time_elapsed,
|
"elapsed": time_elapsed,
|
||||||
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
"timestamp": datetime.now().strftime(
|
||||||
line=decoded_line,
|
"%Y-%m-%d %H:%M:%S"
|
||||||
name=name,
|
),
|
||||||
command=command,
|
"line": decoded_line,
|
||||||
)
|
"name": name,
|
||||||
|
"command": command,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
time_previous = time.time()
|
time_previous = time.time()
|
||||||
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
read_output(
|
read_output(self, f"{process_name}:stdout", command, process.stdout),
|
||||||
self, "{}:stdout".format(process_name), command, process.stdout
|
read_output(self, f"{process_name}:stderr", process, process.stderr),
|
||||||
),
|
|
||||||
read_output(
|
|
||||||
self, "{}:stderr".format(process_name), process, process.stderr
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
log.info(
|
log.info(
|
||||||
"Process {}:{} exited with {}.".format(
|
f"Process {process_name}:{command} exited with {process.returncode}."
|
||||||
process_name, command, process.returncode
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
log.error(
|
log.error(
|
||||||
"Process {}:{} exited with {}.".format(
|
f"Process {process_name}:{command} exited with {process.returncode}."
|
||||||
process_name, command, process.returncode
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def start_processes(self, app):
|
async def start_processes(self, app):
|
||||||
for x, command in enumerate(self.commands):
|
for x, command in enumerate(self.commands):
|
||||||
self.processes[command] = asyncio.create_task(
|
self.processes[command] = asyncio.create_task(
|
||||||
self.run_process("process-{}".format(x), command)
|
self.run_process(f"process-{x}", command)
|
||||||
)
|
)
|
||||||
# asyncio.create_task(asyncio.gather(*self.processes.values()))
|
# asyncio.create_task(asyncio.gather(*self.processes.values()))
|
||||||
|
|
||||||
@ -324,6 +319,6 @@ def cli():
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
app = Zhurnal(commands=args.commands)
|
app = Zhurnal(commands=args.commands)
|
||||||
for command in args.commands:
|
for command in args.commands:
|
||||||
log.info("Preparing execution of {}.".format(command))
|
log.info(f"Preparing execution of {command}.")
|
||||||
log.info("Host: {} Port: {}".format(args.host, args.port))
|
log.info(f"Host: {args.host} Port: {args.port}")
|
||||||
web.run_app(app, host=args.host, port=args.port)
|
web.run_app(app, host=args.host, port=args.port)
|
||||||
|
Loading…
Reference in New Issue
Block a user