aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-24 12:29:10 +0300
committerFrederick Muriuki Muriithi2024-01-24 12:29:10 +0300
commit07deef46a3f3ba53cc632a9381fb25c55e1017b1 (patch)
treea2f4fd1c9f9f69ed774ceff7d0cc5549f630bf9e /scripts
parent96c600723726c3391532d86d17183bea960ece57 (diff)
downloadgn-uploader-07deef46a3f3ba53cc632a9381fb25c55e1017b1.tar.gz
Checks: Update code and tests to ensure all checks pass.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/worker.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/worker.py b/scripts/worker.py
index 17d6e06..0eb9ea5 100644
--- a/scripts/worker.py
+++ b/scripts/worker.py
@@ -6,6 +6,7 @@ import argparse
import traceback
import subprocess
from time import sleep
+from datetime import timedelta
from tempfile import TemporaryDirectory
from redis import Redis
@@ -31,8 +32,8 @@ def parse_args():
def run_job(rconn: Redis, job: dict, redisprefix: str):
"Run the actual job."
- jobid = job["job_id"]
try:
+ jobid = job["jobid"]
with TemporaryDirectory() as tmpdir:
stderrpath = f"{tmpdir}/{jobid}.stderr"
with open(stderrpath, "w+b") as tmpfl:
@@ -41,8 +42,11 @@ def run_job(rconn: Redis, job: dict, redisprefix: str):
stderr=tmpfl) as process:
while process.poll() is None:
jobs.update_status(rconn, redisprefix, jobid, "running")
- jobs.update_stdout_stderr(
- rconn, redisprefix, jobid, process.stdout.read1(), "stdout")
+ jobs.update_stdout_stderr(rconn,
+ redisprefix,
+ jobid,
+ process.stdout.read1(),#type: ignore[union-attr]
+ "stdout")
sleep(1)
jobs.update_status(
@@ -71,11 +75,11 @@ def main():
job = jobs.job(rconn, args.redisprefix, args.job_id)
if job:
return run_job(rconn, job, args.redisprefix)
- jobs.update_status(rconn, args.job_id, "error")
- fqjobid = jobs.job_key(redisprefix, args.jobid)
+ jobs.update_status(rconn, args.redisprefix, args.job_id, "error")
+ fqjobid = jobs.job_key(args.redisprefix, args.jobid)
rconn.hset(fqjobid, "stderr", f"No such job. '{args.job_id}'.")
- redis_conn.expire(name=job_key(args.redisprefix, args.job_id),
- time=timedelta(seconds=(2 * 60 * 60)))
+ rconn.expire(name=jobs.job_key(args.redisprefix, args.job_id),
+ time=timedelta(seconds=(2 * 60 * 60)))
print(f"No such job. '{args.job_id}'.", file=sys.stderr)
return 2
return 3