diff options
author | Frederick Muriuki Muriithi | 2022-09-08 09:37:22 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-09-08 09:37:22 +0300 |
commit | a7e9e94cfafcdee11a68d440a71fb4936c9af82b (patch) | |
tree | f9cbeb3646b32d3bf3e539867376e3db7c1abda9 | |
parent | 38af157b22566cf2bc28d69ac1d18c878321e607 (diff) | |
download | gn-uploader-a7e9e94cfafcdee11a68d440a71fb4936c9af82b.tar.gz |
Use sys.executable and setup default environment
Use the sys.executable to get the correct python binary to run the
external processes, and setup the environment to point to the correct
PYTHONPATH.
-rw-r--r-- | qc_app/jobs.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/qc_app/jobs.py b/qc_app/jobs.py index 9b350b7..dc9ba92 100644 --- a/qc_app/jobs.py +++ b/qc_app/jobs.py @@ -1,11 +1,13 @@ """Handle jobs""" import os +import sys import shlex import subprocess from uuid import uuid4 from datetime import timedelta from redis import Redis +from flask import current_app as app def error_filename(job_id, error_dir): "Compute the path of the file where errors will be dumped." @@ -29,7 +31,7 @@ def build_file_verification_job( "Build a file verification job" job_id = str(uuid4()) command = [ - "python3", "-m", "scripts.validate_file", filetype, filepath, redisurl, + sys.executable, "-m", "scripts.validate_file", filetype, filepath, redisurl, job_id ] return __init_job__( @@ -44,8 +46,8 @@ def data_insertion_job(# pylint: disable=[too-many-arguments] ttl_seconds: int) -> dict: "Build a data insertion job" command = [ - "python3", "-m", "scripts.insert_data", filetype, filepath, speciesid, - platformid, datasetid, databaseuri, redisuri + sys.executable, "-m", "scripts.insert_data", filetype, filepath, + speciesid, platformid, datasetid, databaseuri, redisuri ] return __init_job__( redis_conn, str(uuid4()), command, "data-insertion", ttl_seconds, { @@ -62,8 +64,9 @@ def launch_job(the_job: dict, redisurl: str, error_dir): "w", encoding="utf-8") as errorfile: subprocess.Popen( # pylint: disable=[consider-using-with] - ["python3", "-m", "scripts.worker", redisurl, job_id], - stderr=errorfile) + [sys.executable, "-m", "scripts.worker", redisurl, job_id], + stderr=errorfile, + env={"PYTHONPATH": ":".join(sys.path)}) return the_job |