fix: percentage

This commit is contained in:
ВашÐdettlaff 2023-03-23 20:49:30 +03:00
parent fcdd61006b
commit 88d66fea8c
5 changed files with 30 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
@ -18,54 +18,24 @@ let
black black
fastapi fastapi
uvicorn uvicorn
(buildPythonPackage rec { redis
pname = "strawberry-graphql"; 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 {
buildInputs = [ buildInputs = [
sp-python sp-python
pkgs.black pkgs.black
pkgs.redis
pkgs.restic
]; ];
shellHook = '' shellHook = ''
PYTHONPATH=${sp-python}/${sp-python.sitePackages} PYTHONPATH=${sp-python}/${sp-python.sitePackages}
# envs set with export and as attributes are treated differently.
# for example. printenv <Name> will not fetch the value of an attribute.
export USE_REDIS_PORT=6379
pkill redis-server
redis-server --bind 127.0.0.1 --port $USE_REDIS_PORT >/dev/null &
# maybe set more env-vars # maybe set more env-vars
''; '';
} }

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 == {}