aboutsummaryrefslogtreecommitdiff
path: root/qc_app/jobs.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-06-15 09:36:18 +0300
committerFrederick Muriuki Muriithi2022-06-15 09:36:18 +0300
commitd2605cb72d7cdbc7d3cc633b94a451c0acd2edbb (patch)
tree8bf992967a750bf4dc71290b78285f6239823816 /qc_app/jobs.py
parent6760d322637a3d875242a66e9c1a784866d7df1d (diff)
downloadgn-uploader-d2605cb72d7cdbc7d3cc633b94a451c0acd2edbb.tar.gz
Fix linting and type errors
Diffstat (limited to 'qc_app/jobs.py')
-rw-r--r--qc_app/jobs.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/qc_app/jobs.py b/qc_app/jobs.py
index e97d175..4e6a11e 100644
--- a/qc_app/jobs.py
+++ b/qc_app/jobs.py
@@ -1,3 +1,4 @@
+"""Handle jobs"""
import os
import shlex
import subprocess
@@ -7,29 +8,32 @@ from datetime import timedelta
from redis import Redis
def error_filename(job_id, error_dir):
+ "Compute the path of the file where errors will be dumped."
return f"{error_dir}/job_{job_id}.error"
-def launch_job(
+def launch_job(# pylint: disable=[too-many-arguments]
redis_conn: Redis, filepath: str, filetype, redisurl, error_dir,
ttl_seconds: int):
"""Launch a job in the background"""
job_id = str(uuid4())
command = [
- "python3", "-m" "scripts.worker", filetype, filepath, redisurl, job_id]
- job = {
+ "python3", "-m", "scripts.worker", filetype, filepath, redisurl, job_id]
+ the_job = {
"job_id": job_id, "command": shlex.join(command), "status": "pending",
"filename": os.path.basename(filepath), "percent": 0
}
- redis_conn.hset(name=job["job_id"], mapping=job)
- redis_conn.expire(name=job["job_id"], time=timedelta(seconds=ttl_seconds))
+ redis_conn.hset(name=the_job["job_id"], mapping=the_job)
+ redis_conn.expire(name=the_job["job_id"], time=timedelta(seconds=ttl_seconds))
if not os.path.exists(error_dir):
os.mkdir(error_dir)
- with open(error_filename(job_id, error_dir), "w") as errorfile:
- subprocess.Popen(command, stderr=errorfile)
+ with open(error_filename(job_id, error_dir),
+ "w",
+ encoding="utf-8") as errorfile:
+ subprocess.Popen(command, stderr=errorfile) # pylint: disable=[consider-using-with]
- return job
+ return the_job
def job(redis_conn, job_id: str):
"Retrieve the job"