From dfb56175278409fc56298890b1ca617d0e00992c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 2 Jun 2022 09:58:05 +0300 Subject: Add an error display to the progress status report Enable the progress status page to show all the errors found at any point during the processing of the file. --- scripts/worker.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'scripts/worker.py') diff --git a/scripts/worker.py b/scripts/worker.py index f4d5b6b..6fab9f9 100644 --- a/scripts/worker.py +++ b/scripts/worker.py @@ -48,6 +48,12 @@ def process_cli_arguments(): return cli_args_valid(parser.parse_args()) +def stream_error(redis_conn, job_id, error): + errors = jsonpickle.decode( + redis_conn.hget(job_id, key="errors") or jsonpickle.encode(tuple())) + redis_conn.hset( + job_id, key="errors", value=jsonpickle.encode(errors + (error,))) + def main(): args = process_cli_arguments() if args is None: @@ -71,15 +77,16 @@ def main(): redis_conn.hset( name=args.job_id, key="message", value="Collecting errors") - if count > 0: - errors = take( - collect_errors(filepath, filetype, strains, progress_indicator), - count) - else: - errors = collect_errors(filepath, filetype, strains, progress_indicator) + error_count = 0 + for error in collect_errors( + filepath, filetype, strains, progress_indicator): + stream_error(redis_conn, args.job_id, error) + + if count > 0: + error_count = error_count + 1 + if error_count >= count: + break - redis_conn.hset( - name=args.job_id, key="errors", value=jsonpickle.encode(errors)) redis_conn.hset(name=args.job_id, key="status", value="success") return 0 -- cgit v1.2.3