~comcloudway/builds.sr.ht

994d5d81742546ba12ff8a459d9beeefabfa65eb — Ignas Kiela 2 years ago 5b995c3
Use requests session to keep connections to build runners alive
1 files changed, 5 insertions(+), 4 deletions(-)

M buildsrht/blueprints/jobs.py
M buildsrht/blueprints/jobs.py => buildsrht/blueprints/jobs.py +5 -4
@@ 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("/~<username>")


@@ 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,