aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-12-03 10:44:14 -0600
committerFrederick Muriuki Muriithi2024-12-03 10:44:14 -0600
commit1d9bb54f82fe36a7b38facb8c3b81f56b699dbda (patch)
treef3c79dc085b9420e5957ef8cc914146110974998 /scripts
parentb35570005abbdcea5ce6447a40421791e287e978 (diff)
downloadgn-uploader-1d9bb54f82fe36a7b38facb8c3b81f56b699dbda.tar.gz
Wrap everything in try-catch to handle errors gracefully.
Put everything in the build_main function within a try-catch block to ensure we capture all exceptions that might occur in different scripts and log them out. This helps with debugging errors in the asynchronous scripts.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/rqtl2/entry.py53
1 files changed, 27 insertions, 26 deletions
diff --git a/scripts/rqtl2/entry.py b/scripts/rqtl2/entry.py
index 2a18aa3..48d89fb 100644
--- a/scripts/rqtl2/entry.py
+++ b/scripts/rqtl2/entry.py
@@ -21,38 +21,39 @@ def build_main(
) -> Callable[[],int]:
"""Build a function to be used as an entry-point for scripts."""
def main():
- logging.basicConfig(
- format=(
- "%(asctime)s - %(levelname)s %(name)s: "
- "(%(pathname)s: %(lineno)d) %(message)s"),
- level=args.loglevel)
- logger = logging.getLogger(loggername)
- check_db(args.databaseuri)
- check_redis(args.redisuri)
- if not args.rqtl2bundle.exists():
- logger.error("File not found: '%s'.", args.rqtl2bundle)
- return 2
+ try:
+ logging.basicConfig(
+ format=(
+ "%(asctime)s - %(levelname)s %(name)s: "
+ "(%(pathname)s: %(lineno)d) %(message)s"),
+ level=args.loglevel)
+ logger = logging.getLogger(loggername)
+ with (Redis.from_url(args.redisuri, decode_responses=True) as rconn,
+ database_connection(args.databaseuri) as dbconn):
+ fqjobid = jobs.job_key(args.redisprefix, args.jobid)
+ rconn.hset(fqjobid, "status", "started")
+ logger.addHandler(setup_redis_logger(
+ rconn,
+ fqjobid,
+ f"{fqjobid}:log-messages",
+ args.redisexpiry))
+ logger.addHandler(StreamHandler(stream=sys.stdout))
+
+ check_db(args.databaseuri)
+ check_redis(args.redisuri)
+ if not args.rqtl2bundle.exists():
+ logger.error("File not found: '%s'.", args.rqtl2bundle)
+ return 2
- with (Redis.from_url(args.redisuri, decode_responses=True) as rconn,
- database_connection(args.databaseuri) as dbconn):
- fqjobid = jobs.job_key(args.redisprefix, args.jobid)
- rconn.hset(fqjobid, "status", "started")
- logger.addHandler(setup_redis_logger(
- rconn,
- fqjobid,
- f"{fqjobid}:log-messages",
- args.redisexpiry))
- logger.addHandler(StreamHandler(stream=sys.stdout))
- try:
returncode = run_fn(dbconn, args, logger)
if returncode == 0:
rconn.hset(fqjobid, "status", "completed:success")
return returncode
rconn.hset(fqjobid, "status", "completed:error")
return returncode
- except Exception as _exc:
- logger.error("The process failed!", exc_info=True)
- rconn.hset(fqjobid, "status", "completed:error")
- return 4
+ except Exception as _exc:# pylint: disable=[broad-except]
+ logger.error("The process failed!", exc_info=True)
+ rconn.hset(fqjobid, "status", "completed:error")
+ return 4
return main