ITISFoundation / osparc-issues

🐼 issue-only repo for the osparc project
3 stars 5 forks source link

User log out: Ask the backend @githk #1153

Open GitHK opened 1 year ago

GitHK commented 1 year ago

Extend dy-sidecar to call an endpoint on the service to check if it is busy:

For jupyters something like the following works as a script:

#!/home/jovyan/.venv/bin/python

import requests

BASE_URL = "http://localhost:8888"
HEADERS = {"accept": "application/json"}

def _get(path: str) -> dict:
    r = requests.get(f'{BASE_URL}{path}', headers=HEADERS)
    return r.json()

json_response = _get("/api/kernels")

are_kernels_busy = False

for kernel_data in json_response:
    kernel_id = kernel_data["id"]

    kernel_info = _get(f"/api/kernels/{kernel_id}")
    if kernel_info["execution_state"] != "idle":
        are_kernels_busy = True

if are_kernels_busy:
    print("kernels are busy")
    raise RuntimeError("Kernels are busy")
else:
    print("kernel free")

Jupiter API https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/jupyter_server/master/jupyter_server/services/api/api.yaml#/kernels/get_api_kernels__kernel_id_

### Tasks
- [x] extend sidecar
- [x] extend Jupiter-math with example to be ported to required services
- [ ] extend S4l
elisabettai commented 12 months ago

@mguidon, @GitHK, I just mention here a feedback from NK: "it is urgent that we have a automatic timeout (default and adjustable: pls propose some) . i logged in with one computer and forgot to logout ... it accumulated to 353 edits ~ US$70 after one night ..."