aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/default_config.py1
-rw-r--r--qc_app/jobs.py6
-rw-r--r--qc_app/parse.py3
3 files changed, 8 insertions, 2 deletions
diff --git a/etc/default_config.py b/etc/default_config.py
index 28da532..76b6b43 100644
--- a/etc/default_config.py
+++ b/etc/default_config.py
@@ -9,3 +9,4 @@ LOG_LEVEL = os.getenv("LOG_LEVEL", "WARNING")
SECRET_KEY = b"<Please! Please! Please! Change This!>"
UPLOAD_FOLDER = "/tmp/qc_app_files"
REDIS_URL = "redis://"
+JOBS_TTL_SECONDS = 1209600 # 14 days
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)
diff --git a/qc_app/parse.py b/qc_app/parse.py
index ec9962b..1a1b686 100644
--- a/qc_app/parse.py
+++ b/qc_app/parse.py
@@ -52,7 +52,8 @@ def parse():
with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn:
job = jobs.launch_job(
rconn, filepath, filetype, app.config["REDIS_URL"],
- f"{app.config['UPLOAD_FOLDER']}/job_errors")
+ f"{app.config['UPLOAD_FOLDER']}/job_errors",
+ app.config["JOBS_TTL_SECONDS"])
return redirect(url_for("parse.parse_status", job_id=job["job_id"]))