aboutsummaryrefslogtreecommitdiff
path: root/scripts/worker.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/worker.py')
-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