11from concurrent .futures import ProcessPoolExecutor
2+ from enum import StrEnum
3+ from typing import ClassVar
24
35import datashare_python
46from datashare_python .config import (
810 WorkerConfig ,
911)
1012from datashare_python .objects import DatashareModel , WorkerPaths
13+ from icij_common .registrable import RegistrableConfig
1114from pydantic import Field
1215
1316_ALL_LOGGERS = [datashare_python .__name__ , __name__ , "__main__" ]
@@ -31,9 +34,37 @@ def to_image_preprocessing_executor(self) -> ProcessPoolExecutor:
3134 return ProcessPoolExecutor (max_workers = self .n_processes )
3235
3336
37+ class PDFConverterType (StrEnum ):
38+ GOTENBERG = "gotenberg"
39+
40+
41+ class PDFConverterConfigBase (DatashareModel , RegistrableConfig ):
42+ registry_key : ClassVar [str ] = Field (frozen = True , default = "type" )
43+ type : ClassVar [PDFConverterType ]
44+
45+
46+ class GotenbergPDFConverterConfig (PDFConverterConfigBase ):
47+ type : ClassVar [PDFConverterType ] = Field (
48+ frozen = True , default = PDFConverterType .GOTENBERG
49+ )
50+ gotenberg_url : str = "http://localhost:3000"
51+ max_retries : int = 5
52+ min_retry_wait_s : float = 5.0
53+ max_retry_wait_s : float = 30.0
54+ max_retry_randomness_s : float = 2.0
55+
56+
57+ # TODO: use a tagged union here when we have more options
58+ PDFConverterConfig = GotenbergPDFConverterConfig
59+
60+
3461class PDFConversionWorkerConfig (DatashareModel ):
3562 max_concurrency : int = 10
3663
64+ pdf_converter : PDFConverterConfig = Field (
65+ default_factory = GotenbergPDFConverterConfig
66+ )
67+
3768
3869class PreprocessingWorkerConfig (DatashareModel ):
3970 target_n_pages_per_batch : int = 200
0 commit comments