mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 05:51:29 +00:00
feat: add nix-collect-garbage job
This commit is contained in:
parent
5ada12d2f3
commit
57ec87bf43
32
selfprivacy_api/jobs/nix_collect_garbage.py
Normal file
32
selfprivacy_api/jobs/nix_collect_garbage.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from selfprivacy_api.jobs import Job, JobStatus, Jobs
|
||||||
|
from selfprivacy_api.utils.huey import huey
|
||||||
|
|
||||||
|
|
||||||
|
@huey.task()
|
||||||
|
def nix_collect_garbage(job: Job):
|
||||||
|
|
||||||
|
Jobs.update(
|
||||||
|
job=job,
|
||||||
|
status=JobStatus.RUNNING,
|
||||||
|
progress=0,
|
||||||
|
status_text="Start cleaning.",
|
||||||
|
)
|
||||||
|
|
||||||
|
output = subprocess.check_output("nix-collect-garbage -d")
|
||||||
|
|
||||||
|
pat = re.compile(r"linking saves ([+-]?\d+\.\d+ \w+).+?([+-]?\d+\.\d+ \w+) freed")
|
||||||
|
match = re.search(
|
||||||
|
pat,
|
||||||
|
output,
|
||||||
|
)
|
||||||
|
|
||||||
|
Jobs.update(
|
||||||
|
job=job,
|
||||||
|
status=JobStatus.FINISHED,
|
||||||
|
progress=100,
|
||||||
|
status_text="Сleaning completed.",
|
||||||
|
result=f"Currently hard linking saves {match.group(1)}, {match.group(2)} freed",
|
||||||
|
)
|
Loading…
Reference in a new issue