99from ingestors .support .cache import CacheSupport
1010from ingestors .support .temp import TempFileSupport
1111from ingestors .exc import ProcessingException
12+ from ingestors import settings
1213
1314log = logging .getLogger (__name__ )
1415
15- TIMEOUT = 3600 # seconds
16- CONVERT_RETRIES = 5
1716
1817PDF_CACHE_ACCESSED = Counter (
1918 "ingestfile_pdf_cache_accessed" ,
@@ -45,7 +44,9 @@ def document_to_pdf(self, unique_tmpdir, file_path, entity):
4544 self .tags .set (key , content_hash )
4645 return pdf_file
4746
48- def _document_to_pdf (self , unique_tmpdir , file_path , entity , timeout = TIMEOUT ):
47+ def _document_to_pdf (
48+ self , unique_tmpdir , file_path , entity , timeout = settings .CONVERT_TIMEOUT
49+ ):
4950 """Converts an office document to PDF."""
5051 file_name = entity_filename (entity )
5152 log .info ("Converting [%s] to PDF" , entity )
@@ -72,17 +73,15 @@ def _document_to_pdf(self, unique_tmpdir, file_path, entity, timeout=TIMEOUT):
7273 file_path ,
7374 ]
7475 try :
75- for attempt in range (1 , CONVERT_RETRIES ):
76+ for attempt in range (1 , settings . CONVERT_RETRIES ):
7677 log .info (
77- f"Starting LibreOffice: %s with timeout %s attempt #{ attempt } /{ CONVERT_RETRIES } " ,
78- cmd ,
79- timeout ,
78+ f"Starting LibreOffice: { cmd } with timeout { timeout } attempt #{ attempt } /{ settings .CONVERT_RETRIES } " ,
8079 )
8180 try :
8281 subprocess .run (cmd , timeout = timeout , check = True )
8382 except Exception as e :
8483 log .info (
85- f"Could not be converted to PDF (attempt { attempt } /{ CONVERT_RETRIES } ): { e } "
84+ f"Could not be converted to PDF (attempt { attempt } /{ settings . CONVERT_RETRIES } ): { e } "
8685 )
8786 continue
8887
@@ -95,7 +94,7 @@ def _document_to_pdf(self, unique_tmpdir, file_path, entity, timeout=TIMEOUT):
9594 log .info (f"Successfully converted { out_file } " )
9695 return out_file
9796 raise ProcessingException (
98- f"Could not be converted to PDF (attempt #{ attempt } /{ CONVERT_RETRIES } )"
97+ f"Could not be converted to PDF (attempt #{ attempt } /{ settings . CONVERT_RETRIES } )"
9998 )
10099 except Exception as e :
101100 raise ProcessingException ("Could not be converted to PDF" ) from e
0 commit comments