FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 5b7486a6 authored by J.W. Smith's avatar J.W. Smith
Browse files

feat: subprocess option to choose log type

A useful function in ProcessorUtils is subprocess_and_log, which builds a subprocess command and write its stdout and stderr to the log handler. Beforehand, failures only ever generated an error message, but there are some use cases where another log type is preferred. This adds a log type option to the function, and uses it in one case where a warning is more appropriate.
parent f91a061c
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,9 @@ def process_in_job_survey(jobPath,status,config,component):
logger.debug('Performing ' + description_long)
try:
subprocess_and_log(ODK_download,description_short,description_long,check=True)
# perform a pull from the ODK server, and if it fails write a warning message
subprocess_and_log(ODK_download,description_short,description_long,log_type='warning',check=True)
except subprocess.CalledProcessError as e:
status.reset('WARNING')
......
......@@ -106,9 +106,16 @@ def get_only_existing_globs(file_globs,inplace=True):
globs_out += [fg]
return globs_out
def subprocess_and_log(cmd,description_short,description_long,check=True,**kwargs):
def subprocess_and_log(cmd,description_short,description_long,check=True,log_type='error',**kwargs):
'''Run a shell command (described by a comma separated list) and send stdout
and stderr to logfile, and raise any exception.'''
and stderr to logfile, and raise any exception.
log_type is a string to determine which log message level to use, must be
one of the logging options: info, debug, warn, warning, error, exception or
fatal.'''
# determine message type to write to log
log_call = getattr(logger,log_type)
try:
process = subprocess.run(
......@@ -126,7 +133,7 @@ def subprocess_and_log(cmd,description_short,description_long,check=True,**kwarg
for line in e.stdout.decode('utf-8').split(r'\n'):
logger.info(f"{description_short} : " + line)
logger.exception(f"Some failure when running {description_long}", exc_info=True)
log_call(f"Some failure when running {description_long}", exc_info=True)
raise
return process
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment