fix: percentage

pull/21/head
ВашÐdettlaff 2023-03-23 20:49:30 +03:00 committed by dettlaff
parent af0129bdfe
commit 03b5a6b5e4
5 changed files with 23 additions and 63 deletions

BIN
dump.rdb Normal file

Binary file not shown.

View File

@ -61,19 +61,19 @@ def parse_line(line):
def stream_process( def stream_process(
stream, stream,
package_equal_to_percent, total_dead_packages,
set_job_status, set_job_status,
): ):
percent = 0 completed_packages = 0
for line in stream: for line in stream:
if "deleting '/nix/store/" in line: if "deleting '/nix/store/" in line:
percent += package_equal_to_percent completed_packages += 1
percent = int((completed_packages / total_dead_packages) * 100)
set_job_status( set_job_status(
status=JobStatus.RUNNING, status=JobStatus.RUNNING,
progress=int(percent), progress=percent,
progress=int(percent),
status_text="Сleaning...", status_text="Сleaning...",
) )
@ -95,7 +95,7 @@ def get_dead_packages(output):
return dead, percent return dead, percent
@huey.task() # @huey.task() # ломает все к фигам
def nix_collect_garbage( def nix_collect_garbage(
job, job,
jobs=Jobs, jobs=Jobs,

0
setup.py Executable file → Normal file
View File

View File

@ -1,6 +1,6 @@
{ pkgs ? import <nixpkgs> { } }: { pkgs ? import <nixos-22.11> { } }:
let let
sp-python = pkgs.python39.withPackages (p: with p; [ sp-python = pkgs.python310.withPackages (p: with p; [
setuptools setuptools
portalocker portalocker
pytz pytz
@ -19,45 +19,7 @@ let
fastapi fastapi
uvicorn uvicorn
redis redis
(buildPythonPackage rec { strawberry-graphql
pname = "strawberry-graphql";
version = "0.123.0";
format = "pyproject";
patches = [
./strawberry-graphql.patch
];
propagatedBuildInputs = [
typing-extensions
python-multipart
python-dateutil
# flask
pydantic
pygments
poetry
# flask-cors
(buildPythonPackage rec {
pname = "graphql-core";
version = "3.2.0";
format = "setuptools";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-huKgvgCL/eGe94OI3opyWh2UKpGQykMcJKYIN5c4A84=";
};
checkInputs = [
pytest-asyncio
pytest-benchmark
pytestCheckHook
];
pythonImportsCheck = [
"graphql"
];
})
];
src = fetchPypi {
inherit pname version;
sha256 = "KsmZ5Xv8tUg6yBxieAEtvoKoRG60VS+iVGV0X6oCExo=";
};
})
]); ]);
in in
pkgs.mkShell { pkgs.mkShell {
@ -65,6 +27,7 @@ pkgs.mkShell {
sp-python sp-python
pkgs.black pkgs.black
pkgs.redis pkgs.redis
pkgs.restic
]; ];
shellHook = '' shellHook = ''
PYTHONPATH=${sp-python}/${sp-python.sitePackages} PYTHONPATH=${sp-python}/${sp-python.sitePackages}

View File

@ -96,26 +96,21 @@ def test_stream_process():
def set_job_status(status, progress, status_text, result=""): def set_job_status(status, progress, status_text, result=""):
log_event.append((status, progress, status_text, result)) log_event.append((status, progress, status_text, result))
stream_process(output_collect_garbage.split("\n"), 20.0, set_job_status) stream_process(output_collect_garbage.split("\n"), 5, set_job_status)
assert log_event == reference assert log_event == reference
def test_nix_collect_garbage(): def test_nix_collect_garbage():
log_event = [] log_event = []
reference = [ reference = [
(JobStatus.RUNNING, 0, "Сalculate the number of dead packages...", ""), (JobStatus.RUNNING, 0, 'Сalculate the number of dead packages...', ''),
(JobStatus.RUNNING, 0, "Found 5 packages to remove!", ""), (JobStatus.RUNNING, 0, 'Found 5 packages to remove!', ''),
(JobStatus.RUNNING, 20, "Сleaning...", ""), (JobStatus.RUNNING, 5, 'Сleaning...', ''),
(JobStatus.RUNNING, 40, "Сleaning...", ""), (JobStatus.RUNNING, 10, 'Сleaning...', ''),
(JobStatus.RUNNING, 60, "Сleaning...", ""), (JobStatus.RUNNING, 15, 'Сleaning...', ''),
(JobStatus.RUNNING, 80, "Сleaning...", ""), (JobStatus.RUNNING, 20, 'Сleaning...', ''),
(JobStatus.RUNNING, 100, "Сleaning...", ""), (JobStatus.RUNNING, 25, 'Сleaning...', ''),
( (JobStatus.FINISHED, 100, 'Сleaning completed.', '425.51 MiB have been cleared'),
JobStatus.FINISHED,
100,
"Сleaning completed.",
"425.51 MiB have been cleared",
),
] ]
def set_job_status(status="", progress="", status_text="", result=""): def set_job_status(status="", progress="", status_text="", result=""):
@ -128,6 +123,8 @@ def test_nix_collect_garbage():
lambda: output_collect_garbage.split("\n"), lambda: output_collect_garbage.split("\n"),
set_job_status, set_job_status,
) )
print("log_event:", log_event)
print("reference:", reference)
assert log_event == reference assert log_event == reference
@ -152,7 +149,7 @@ def test_nix_collect_garbage_zero_trash():
assert log_event == reference assert log_event == reference
# андр констракнш
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_graphql_nix_collect_garbage(): async def test_graphql_nix_collect_garbage():
query = """ query = """
@ -166,6 +163,6 @@ async def test_graphql_nix_collect_garbage():
) )
sub = await schema_for_garbage.subscribe(query) sub = await schema_for_garbage.subscribe(query)
for result in sub: async for result in sub:
assert not result.errors assert not result.errors
assert result.data == {} assert result.data == {}