diff options
author | Frederick Muriuki Muriithi | 2022-06-02 11:12:38 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-06-02 12:56:28 +0300 |
commit | 219248568252e7291f20105ce589c87c5a85f433 (patch) | |
tree | 2145cbb97cdf54e2cc32f31027c024c8c336b45b /qc_app/jobs.py | |
parent | dfb56175278409fc56298890b1ca617d0e00992c (diff) | |
download | gn-uploader-219248568252e7291f20105ce589c87c5a85f433.tar.gz |
Expire the jobs in 14 days by default
Diffstat (limited to 'qc_app/jobs.py')
-rw-r--r-- | qc_app/jobs.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/qc_app/jobs.py b/qc_app/jobs.py index 4d3dba6..e97d175 100644 --- a/qc_app/jobs.py +++ b/qc_app/jobs.py @@ -2,13 +2,16 @@ import os import shlex import subprocess from uuid import uuid4 +from datetime import timedelta from redis import Redis def error_filename(job_id, error_dir): return f"{error_dir}/job_{job_id}.error" -def launch_job(redis_conn: Redis, filepath, filetype, redisurl, error_dir): +def launch_job( + redis_conn: Redis, filepath: str, filetype, redisurl, error_dir, + ttl_seconds: int): """Launch a job in the background""" job_id = str(uuid4()) command = [ @@ -18,6 +21,7 @@ def launch_job(redis_conn: Redis, filepath, filetype, redisurl, error_dir): "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)) if not os.path.exists(error_dir): os.mkdir(error_dir) |