mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 14:01:30 +00:00
fix: percentage
This commit is contained in:
parent
fcdd61006b
commit
88d66fea8c
|
@ -61,19 +61,19 @@ def parse_line(line):
|
|||
|
||||
def stream_process(
|
||||
stream,
|
||||
package_equal_to_percent,
|
||||
total_dead_packages,
|
||||
set_job_status,
|
||||
):
|
||||
percent = 0
|
||||
completed_packages = 0
|
||||
|
||||
for line in stream:
|
||||
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(
|
||||
status=JobStatus.RUNNING,
|
||||
progress=int(percent),
|
||||
progress=int(percent),
|
||||
progress=percent,
|
||||
status_text="Сleaning...",
|
||||
)
|
||||
|
||||
|
@ -95,7 +95,7 @@ def get_dead_packages(output):
|
|||
return dead, percent
|
||||
|
||||
|
||||
@huey.task()
|
||||
# @huey.task() # ломает все к фигам
|
||||
def nix_collect_garbage(
|
||||
job,
|
||||
jobs=Jobs,
|
||||
|
|
52
shell.nix
52
shell.nix
|
@ -1,6 +1,6 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
{ pkgs ? import <nixos-22.11> { } }:
|
||||
let
|
||||
sp-python = pkgs.python39.withPackages (p: with p; [
|
||||
sp-python = pkgs.python310.withPackages (p: with p; [
|
||||
setuptools
|
||||
portalocker
|
||||
pytz
|
||||
|
@ -18,54 +18,24 @@ let
|
|||
black
|
||||
fastapi
|
||||
uvicorn
|
||||
(buildPythonPackage rec {
|
||||
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=";
|
||||
};
|
||||
})
|
||||
redis
|
||||
strawberry-graphql
|
||||
]);
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = [
|
||||
sp-python
|
||||
pkgs.black
|
||||
pkgs.redis
|
||||
pkgs.restic
|
||||
];
|
||||
shellHook = ''
|
||||
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
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -96,26 +96,21 @@ def test_stream_process():
|
|||
def set_job_status(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
|
||||
|
||||
|
||||
def test_nix_collect_garbage():
|
||||
log_event = []
|
||||
reference = [
|
||||
(JobStatus.RUNNING, 0, "Сalculate the number of dead packages...", ""),
|
||||
(JobStatus.RUNNING, 0, "Found 5 packages to remove!", ""),
|
||||
(JobStatus.RUNNING, 20, "Сleaning...", ""),
|
||||
(JobStatus.RUNNING, 40, "Сleaning...", ""),
|
||||
(JobStatus.RUNNING, 60, "Сleaning...", ""),
|
||||
(JobStatus.RUNNING, 80, "Сleaning...", ""),
|
||||
(JobStatus.RUNNING, 100, "Сleaning...", ""),
|
||||
(
|
||||
JobStatus.FINISHED,
|
||||
100,
|
||||
"Сleaning completed.",
|
||||
"425.51 MiB have been cleared",
|
||||
),
|
||||
(JobStatus.RUNNING, 0, 'Сalculate the number of dead packages...', ''),
|
||||
(JobStatus.RUNNING, 0, 'Found 5 packages to remove!', ''),
|
||||
(JobStatus.RUNNING, 5, 'Сleaning...', ''),
|
||||
(JobStatus.RUNNING, 10, 'Сleaning...', ''),
|
||||
(JobStatus.RUNNING, 15, 'Сleaning...', ''),
|
||||
(JobStatus.RUNNING, 20, 'Сleaning...', ''),
|
||||
(JobStatus.RUNNING, 25, 'Сleaning...', ''),
|
||||
(JobStatus.FINISHED, 100, 'Сleaning completed.', '425.51 MiB have been cleared'),
|
||||
]
|
||||
|
||||
def set_job_status(status="", progress="", status_text="", result=""):
|
||||
|
@ -128,6 +123,8 @@ def test_nix_collect_garbage():
|
|||
lambda: output_collect_garbage.split("\n"),
|
||||
set_job_status,
|
||||
)
|
||||
print("log_event:", log_event)
|
||||
print("reference:", reference)
|
||||
|
||||
assert log_event == reference
|
||||
|
||||
|
@ -152,7 +149,7 @@ def test_nix_collect_garbage_zero_trash():
|
|||
|
||||
assert log_event == reference
|
||||
|
||||
|
||||
# андр констракнш
|
||||
@pytest.mark.asyncio
|
||||
async def test_graphql_nix_collect_garbage():
|
||||
query = """
|
||||
|
@ -166,6 +163,6 @@ async def test_graphql_nix_collect_garbage():
|
|||
)
|
||||
|
||||
sub = await schema_for_garbage.subscribe(query)
|
||||
for result in sub:
|
||||
async for result in sub:
|
||||
assert not result.errors
|
||||
assert result.data == {}
|
||||
|
|
Loading…
Reference in a new issue