Add ProcessResult to auto_process.common

This commit is contained in:
Labrys of Knossos 2018-12-27 09:08:28 -05:00 committed by Lizband
commit 8c4353bc90
5 changed files with 111 additions and 44 deletions

View file

@ -6,6 +6,7 @@ import requests
import core
from core import logger
from core.auto_process.common import ProcessResult
from core.utils import convert_to_ascii, remote_dir, server_responding
requests.packages.urllib3.disable_warnings()
@ -28,7 +29,10 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root)
if not server_responding(url):
logger.error("Server did not respond. Exiting", section)
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
return ProcessResult(
message="{0}: Failed to post-process - {0} did not respond.".format(section),
status_code=1,
)
input_name, dir_name = convert_to_ascii(input_name, dir_name)
clean_name, ext = os.path.splitext(input_name)
@ -54,10 +58,16 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
r = requests.post(url, params=params, stream=True, verify=False, timeout=(30, 300))
except requests.ConnectionError:
logger.error("Unable to open URL", section)
return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)]
return ProcessResult(
message="{0}: Failed to post-process - Unable to connect to {0}".format(section),
status_code=1
)
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
logger.error("Server returned status {0}".format(r.status_code), section)
return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)]
return ProcessResult(
message="{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code),
status_code=1,
)
result = r.content
if not type(result) == list:
@ -70,7 +80,13 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
if success:
logger.postprocess("SUCCESS: This issue has been processed successfully", section)
return [0, "{0}: Successfully post-processed {1}".format(section, input_name)]
return ProcessResult(
message="{0}: Successfully post-processed {1}".format(section, input_name),
status_code=0,
)
else:
logger.warning("The issue does not appear to have successfully processed. Please check your Logs", section)
return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)]
return ProcessResult(
message="{0}: Failed to post-process - Returned log from {0} was not as expected.".format(section),
status_code=1,
)