Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front build gui #7

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,6 @@ cython_debug/
/df_designer_front/.vscode

./flows.json
*.sqlite
*.sqlite

flows.json
119 changes: 119 additions & 0 deletions builds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[
{
"FULL INFO BUILD && FULL IMFO RUNS": "для информации",
"id": "build1",
"timestamp": "12314235246",
"preset_name": "build_preset_1",
"status": "completed",
"logs": ["log_string_1", "log_string_2", "etc."],
"logs_path": "/something/...",
"runs": [
{
"id": "run1",
"timestamp": "133254314",
"preset_name": "run_preset_1",
"status": "failed",
"logs": ["log_string_1", "log_string_2", "etc."],
"logs_path": "/something/...",
"build_id": "build1"
},
{
"id": "run2",
"timestamp": "133254314",
"preset_name": "run_preset_2",
"status": "completed",
"logs": ["log_string_1", "log_string_2", "etc."],
"logs_path": "/something/...",
"build_id": "build1"
}
]
},
{
"BUILDS MINIFY && RUNS MINIFY": "по эндпоинту /bot/builds приходит список вот таких билдов и вот таких запусков",
"builds": [
{
"id": "build1",
"timestamp": "12314235246",
"preset_name": "build_preset_1",
"status": "completed",
"runs": [
{
"id": "run1",
"timestamp": "133254314",
"preset_name": "run_preset_1",
"status": "failed",
"build_id": "build1"
},
{
"id": "run2",
"timestamp": "133254314",
"preset_name": "run_preset_2",
"status": "completed",
"build_id": "build1"
}
]
},
{
"id": "build2",
"timestamp": "12314235246",
"preset_name": "build_preset_1",
"status": "completed",
"runs": [
{
"id": "run1",
"timestamp": "133254314",
"preset_name": "run_preset_1",
"status": "failed",
"build_id": "build2"
},
{
"id": "run2",
"timestamp": "133254314",
"preset_name": "run_preset_2",
"status": "completed",
"build_id": "build2"
}
]
}
]
},
{
"FULL INFO BUILD && RUNS MINIFY": "по эндпоинту /bot/builds/?id={id} ///потенциально задел на то, что можно будет любое поле передать параметром для поиска",
"build": {
"id": "build{id}",
"timestamp": "12314235246",
"preset_name": "build_preset_1",
"status": "completed",
"logs": ["log_string_1", "log_string_2", "etc."],
"logs_path": "/something/...",
"runs": [
{
"id": "run1",
"timestamp": "133254314",
"preset_name": "run_preset_1",
"status": "failed",
"build_id": "build1"
},
{
"id": "run2",
"timestamp": "133254314",
"preset_name": "run_preset_2",
"status": "completed",
"build_id": "build1"
}
]
}
},
{
"RUN FULL INFO": "по эндпоинту /bot/runs/?id={id} ///потенциально задел на то, что можно будет любое поле передать параметром для поиска",
"run": {
"id": "run{id}",
"timestamp": "133254314",
"preset_name": "run_preset_2",
"status": "completed",
"logs": ["log_string_1", "log_string_2", "etc."],
"logs_path": "/something/...",
"build_id": "build1"
}
}
]
53 changes: 53 additions & 0 deletions df_designer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import asyncio
import aiofiles

from df_designer.db_requests import run_insert, run_update
from df_designer.logic import create_directory_to_log, log_file_name
from df_designer.settings import app


class Proc:
async def start(self):
"""Start the process."""
create_directory_to_log()
file_for_log = log_file_name()
self.id_record = await run_insert(file_for_log, "start")
async with aiofiles.open(file_for_log, "w", encoding="UTF-8") as file:
self.process = await asyncio.create_subprocess_exec(
# "ping",
# "localhost",
# "python",
# "correct_script.py",
# "error_script.py",
*app.cmd_to_run.split(" "),
stdout=file.fileno(),
stderr=file.fileno(),
)
return self.process.pid

async def check_status(self):
"""Check status process and write fo database."""
while True:
await asyncio.sleep(1)
if self.process.returncode is not None:
if self.process.returncode == 0:
await run_update(self.id_record, "stop")
break
elif self.process.returncode > 0:
await run_update(self.id_record, "error")
break

async def stop(self):
"""Stop the process."""
self.process.terminate()
await run_update(self.id_record, "terminate")

async def status(self):
"""Return the status of the process."""
return self.process.returncode

async def pid(self):
return self.process.pid


process = Proc()
47 changes: 47 additions & 0 deletions df_designer/db_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Any
from df_designer.db_connection import Logs, async_session
from sqlalchemy import insert, select, update
import time
from pathlib import Path


async def run_insert(file_for_log: Path, process_status: str):
"""Insert process data."""
async with async_session() as session:
stmt = (
insert(Logs)
.values(
datetime=time.time(),
path=str(Path(file_for_log).absolute()),
status=process_status,
)
.returning()
)
id_record = await session.execute(stmt)
await session.commit()
return id_record


async def run_update(id_record: Any, process_status: str):
"""Update process data."""
async with async_session() as session:
stmt = (
update(Logs)
.values(status=process_status)
.where(Logs.id == id_record.inserted_primary_key[0])
)
await session.execute(stmt)
await session.commit()


async def run_last():
"""Return last run path."""
async with async_session() as session:
# stmt = select(Runs.path).where(Runs.status == "start").order_by(Runs.datetime)
stmt = (
select(Logs.path)
.order_by(Logs.datetime.desc())
.where(Logs.status == "start")
)
result = await session.execute(stmt)
return result.scalar()
15 changes: 15 additions & 0 deletions df_designer/logic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json
import os
from datetime import datetime
from pathlib import Path
from typing import Any

import aiofiles
from pydantic import Json

from df_designer.settings import app


async def save_data(path: Path, data: dict[str, str]):
"""Save the json config."""
Expand All @@ -20,3 +23,15 @@ async def get_data(path: Path) -> Json[Any]:
return json.loads(await file.read())
else:
return {}


def log_file_name() -> Path:
"""Create title a log."""
file_log_name = datetime.now().strftime("%Y_%m_%d_%H_%M_%s") + ".txt"
return Path(app.dir_logs, file_log_name)


def create_directory_to_log():
"""Create directory to log files."""
if not Path(app.dir_logs).exists():
Path(app.dir_logs).mkdir()
Loading