implemented the rest of the async functions and changed the way multithreading works

This commit is contained in:
Kikimanox
2022-09-19 17:11:59 +02:00
parent 9e82f3b93a
commit 916b2bef2a
7 changed files with 174 additions and 47 deletions
@@ -2,7 +2,6 @@ import connexion
from swagger_server.models.oznaci_besedilo_async_body import OznaciBesediloAsyncBody # noqa: E501
from swagger_server.requets_db.models.vrsta import (JobManager)
from swagger_server.utils import txt_utils
def get_text(body): # noqa: E501
@@ -17,6 +16,8 @@ def get_text(body): # noqa: E501
"""
if connexion.request.is_json:
body = OznaciBesediloAsyncBody.from_dict(connexion.request.get_json()) # noqa: E501
else:
return "Request in wrong format", 400
# conllu = cl_utils.raw_text_to_conllu(body.besedilo)
# return conllu
job, is_old_job = JobManager.create_job(2, body.besedilo)
@@ -37,7 +38,11 @@ def get_conllu_from_file_async(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
job, is_old_job = JobManager.create_job(12, file)
if job is None:
return "Something went wrong", 500
ret = {'check_job_url': f'{connexion.request.url_root}/job/{job.id}'}
return ret, 200
def get_conllu_from_file_ocr_async(file=None): # noqa: E501
@@ -50,7 +55,11 @@ def get_conllu_from_file_ocr_async(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
job, is_old_job = JobManager.create_job(32, file)
if job is None:
return "Something went wrong", 500
ret = {'check_job_url': f'{connexion.request.url_root}/job/{job.id}'}
return ret, 200
def get_text_from_doc_async(file=None): # noqa: E501
@@ -63,7 +72,11 @@ def get_text_from_doc_async(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
job, is_old_job = JobManager.create_job(1, file)
if job is None:
return "Something went wrong", 500
ret = {'check_job_url': f'{connexion.request.url_root}/job/{job.id}'}
return ret, 200
def get_text_from_file_ocr_async(file=None): # noqa: E501
@@ -76,4 +89,8 @@ def get_text_from_file_ocr_async(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
job, is_old_job = JobManager.create_job(3, file)
if job is None:
return "Something went wrong", 500
ret = {'check_job_url': f'{connexion.request.url_root}/job/{job.id}'}
return ret, 200