Source code for kappa_sdk.document_extensions
import time
from typing import List, cast, Dict, Any
from .rest_api import RestAPI
from .service_enum import ServiceEnum
from .kw_module_enum import KWModuleEnum
_MODULE_TO_PREPROCESSING_KEY = {
KWModuleEnum.saphir: "PTADocumentPreProcessing",
KWModuleEnum.topaze: "RTADocumentPreProcessing",
KWModuleEnum.rubis: "NUMDocumentPreProcessing",
}
[docs]
def wait_document_preprocessing(rest_api: RestAPI, field_id: str, file_id: str, module: KWModuleEnum) -> None:
"""
Wait until the document preprocessing is finished
Parameters
----------
rest_api:
A :class:`RestAPI`
field_id:
The field id
file_id:
The file id
module:
The KW module type
"""
job_name = _MODULE_TO_PREPROCESSING_KEY[module]
is_preprocessing_finished = False
while not is_preprocessing_finished:
time.sleep(5)
jobs = cast(List[Dict[str, Any]],
rest_api.get(ServiceEnum.automation, '/v1/automation/job/all?fieldId={}&jobName={}&targetId={}'.format(field_id, job_name, file_id)))
for job in jobs:
if job["status"] != "Idle":
is_preprocessing_finished = False
break
else:
is_preprocessing_finished = True