From 2f84b2eb1fecab4c381ad2dfd31277717cc9df2d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 2 Jun 2022 12:57:18 +0300 Subject: Enable user abortion of file parsing Enable the user to abort the background parsing of the file. --- scripts/worker.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/worker.py b/scripts/worker.py index 6fab9f9..0ef5ae5 100644 --- a/scripts/worker.py +++ b/scripts/worker.py @@ -54,6 +54,16 @@ def stream_error(redis_conn, job_id, error): redis_conn.hset( job_id, key="errors", value=jsonpickle.encode(errors + (error,))) +def make_user_aborted(redis_conn, job_id): + def __aborted__(): + user_aborted = bool(int( + redis_conn.hget(name=job_id, key="user_aborted") or "0")) + if user_aborted: + redis_conn.hset(name=job_id, key="status", value="aborted") + + return user_aborted + return __aborted__ + def main(): args = process_cli_arguments() if args is None: @@ -79,7 +89,8 @@ def main(): error_count = 0 for error in collect_errors( - filepath, filetype, strains, progress_indicator): + filepath, filetype, strains, progress_indicator, + make_user_aborted(redis_conn, args.job_id)): stream_error(redis_conn, args.job_id, error) if count > 0: -- cgit v1.2.3