Skip to content

Commit

Permalink
api: drop very legacy API
Browse files Browse the repository at this point in the history
It was used some years ago but isn't used in any LuCI/auc/selector
anymore.

Signed-off-by: Paul Spooren <[email protected]>
  • Loading branch information
aparcar committed May 5, 2024
1 parent c0104cd commit 2b87e3b
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions asu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,88 +272,3 @@ def api_v1_build_post():
redis_client().incr("stats:cache-hit")

return return_job_v1(job)


# legacy /api/build
@bp.route("/branches")
def api_branches():
return jsonify(list(current_app.config["OVERVIEW"]["branches"].values()))


def return_job(job):
response = {}
if job.meta:
response.update(job.meta)

status = 500

if job.is_failed:
response["message"] = job.meta["detail"]

elif job.is_queued:
status = 202
response = {
"status": job.get_status(),
"queue_position": job.get_position() or 0,
}

elif job.is_started:
status = 202
response = {
"status": job.get_status(),
}

elif job.is_finished:
status = 200
response.update(job.result)
response["build_at"] = job.ended_at

response["enqueued_at"] = job.enqueued_at
response["request_hash"] = job.id

current_app.logger.debug(f"Response {response} with status {status}")
return response, status


@bp.route("/build/<path:request_hash>", methods=["GET"])
def api_build_get(request_hash):
job = get_queue().fetch_job(request_hash)
if not job:
return {"status": "not_found"}, 404

return return_job(job)


@bp.route("/build", methods=["POST"])
def api_build_post():
req = request.get_json()
current_app.logger.debug(f"req {req}")
request_hash = get_request_hash(req)
job = get_queue().fetch_job(request_hash)
response = {}
status = 200
result_ttl = "24h"
failure_ttl = "12h"

if job is None:
response, status = validate_request(req)
if response:
return response, status

req["public_path"] = current_app.config["PUBLIC_PATH"]
if current_app.config.get("CACHE_PATH"):
req["cache_path"] = current_app.config.get("CACHE_PATH")
req["upstream_url"] = current_app.config["UPSTREAM_URL"]
req["branch_data"] = current_app.config["BRANCHES"][req["branch"]]
req["request_hash"] = request_hash

job = get_queue().enqueue(
build,
req,
job_id=request_hash,
result_ttl=result_ttl,
failure_ttl=failure_ttl,
job_timeout="10m",
)

return return_job(job)

0 comments on commit 2b87e3b

Please sign in to comment.