Formatted.
All checks were successful
Build and test Zhurnal / Test (push) Successful in 1m0s

This commit is contained in:
retoor 2024-12-01 08:50:26 +01:00
parent a2354c2ba7
commit 0aa8955b4a

View File

@ -1,12 +1,13 @@
from aiohttp import web
from typing import List
import shlex
import asyncio
import json
from datetime import datetime
from zhurnal import log
import shlex
import time
from datetime import datetime
from typing import List
from aiohttp import web
from zhurnal import log
index_html = """
<!DOCTYPE html>
@ -244,7 +245,7 @@ class Zhurnal(web.Application):
stdout=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):
time_previous = 0
@ -259,42 +260,36 @@ class Zhurnal(web.Application):
for client in app.clients:
await client.send_str(
json.dumps(
dict(
elapsed=time_elapsed,
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
line=decoded_line,
name=name,
command=command,
)
{
"elapsed": time_elapsed,
"timestamp": datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"
),
"line": decoded_line,
"name": name,
"command": command,
}
)
)
time_previous = time.time()
await asyncio.gather(
read_output(
self, "{}:stdout".format(process_name), command, process.stdout
),
read_output(
self, "{}:stderr".format(process_name), process, process.stderr
),
read_output(self, f"{process_name}:stdout", command, process.stdout),
read_output(self, f"{process_name}:stderr", process, process.stderr),
)
if process.returncode == 0:
log.info(
"Process {}:{} exited with {}.".format(
process_name, command, process.returncode
)
f"Process {process_name}:{command} exited with {process.returncode}."
)
else:
log.error(
"Process {}:{} exited with {}.".format(
process_name, command, process.returncode
)
f"Process {process_name}:{command} exited with {process.returncode}."
)
async def start_processes(self, app):
for x, command in enumerate(self.commands):
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()))
@ -324,6 +319,6 @@ def cli():
args = parse_args()
app = Zhurnal(commands=args.commands)
for command in args.commands:
log.info("Preparing execution of {}.".format(command))
log.info("Host: {} Port: {}".format(args.host, args.port))
log.info(f"Preparing execution of {command}.")
log.info(f"Host: {args.host} Port: {args.port}")
web.run_app(app, host=args.host, port=args.port)