Passed
Pull Request — master (#1111)
by
unknown
02:21
created

ocrd_network.logging   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 29
dl 0
loc 49
rs 10
c 0
b 0
f 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A get_cache_processing_requests_logging_file_path() 0 2 1
A get_processor_server_logging_file_path() 0 2 1
A get_root_logging_dir() 0 7 2
A get_processing_worker_logging_file_path() 0 2 1
A get_cache_locked_pages_logging_file_path() 0 2 1
A get_processing_job_logging_file_path() 0 2 1
A get_processing_server_logging_file_path() 0 2 1
A get_mets_server_logging_file_path() 0 2 1
1
from pathlib import Path
2
from ocrd_utils import safe_filename
3
4
5
OCRD_NETWORK_MODULES = [
6
    "mets_servers",
7
    "processing_jobs",
8
    "processing_servers",
9
    "processing_workers",
10
    "processor_servers"
11
]
12
13
14
def get_root_logging_dir(module_name: str) -> Path:
15
    if module_name not in OCRD_NETWORK_MODULES:
16
        raise ValueError(f"Invalid module name: {module_name}, should be one of: {OCRD_NETWORK_MODULES}")
17
    # TODO: Utilize env variable to set the root
18
    module_log_dir = Path("/tmp", "ocrd_network_logs", module_name)
19
    module_log_dir.mkdir(parents=True, exist_ok=True)
20
    return module_log_dir
21
22
23
def get_cache_locked_pages_logging_file_path() -> Path:
24
    return get_root_logging_dir("processing_servers") / "cache_locked_pages.log"
25
26
27
def get_cache_processing_requests_logging_file_path() -> Path:
28
    return get_root_logging_dir("processing_servers") / "cache_processing_requests.log"
29
30
31
def get_processing_job_logging_file_path(job_id: str) -> Path:
32
    return get_root_logging_dir("processing_jobs") / f"{job_id}.log"
33
34
35
def get_processing_server_logging_file_path(pid: int) -> Path:
36
    return get_root_logging_dir("processing_servers") / f"server.{pid}.log"
37
38
39
def get_processing_worker_logging_file_path(processor_name: str, pid: int) -> Path:
40
    return get_root_logging_dir("processing_workers") / f"worker.{pid}.{processor_name}.log"
41
42
43
def get_processor_server_logging_file_path(processor_name: str, pid: int) -> Path:
44
    return get_root_logging_dir("processor_servers") / f"server.{pid}.{processor_name}.log"
45
46
47
def get_mets_server_logging_file_path(mets_path: str) -> Path:
48
    return get_root_logging_dir("mets_servers") / f"{safe_filename(mets_path)}.log"
49