From 994d5d81742546ba12ff8a459d9beeefabfa65eb Mon Sep 17 00:00:00 2001 From: Ignas Kiela Date: Wed, 8 Dec 2021 00:09:25 +0200 Subject: [PATCH] Use requests session to keep connections to build runners alive --- buildsrht/blueprints/jobs.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/buildsrht/blueprints/jobs.py b/buildsrht/blueprints/jobs.py index 31897cb..ea400c8 100644 --- a/buildsrht/blueprints/jobs.py +++ b/buildsrht/blueprints/jobs.py @@ -33,6 +33,7 @@ metrics = type("metrics", tuple(), { ] }) +requests_session = requests.Session() def tags(tags): if not tags: @@ -268,7 +269,7 @@ def cancel(job_id): abort(404) if job.owner_id != current_user.id and current_user.user_type != UserType.admin: abort(401) - requests.post(f"http://{job.runner}/job/{job.id}/cancel") + requests_session.post(f"http://{job.runner}/job/{job.id}/cancel") return redirect("/~" + current_user.username + "/job/" + str(job.id)) @jobs.route("/~") @@ -435,14 +436,14 @@ def job_by_id(username, job_id): if not log: metrics.buildsrht_logcache_miss.inc() try: - r = requests.head(log_url) + r = requests_session.head(log_url) cl = int(r.headers["Content-Length"]) if cl > log_max: - r = requests.get(log_url, headers={ + r = requests_session.get(log_url, headers={ "Range": f"bytes={cl-log_max}-{cl-1}", }, timeout=3) else: - r = requests.get(log_url, timeout=3) + r = requests_session.get(log_url, timeout=3) if r.status_code >= 200 and r.status_code <= 299: log = { "name": name, -- 2.38.5