Skip to content

Commit 49cf295

Browse files
committed
fix(sessions): get the session status from the pod state (reanahub#611)
Closes reanahub/reana-ui#408
1 parent 7896c61 commit 49cf295

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

reana_workflow_controller/k8s.py

+17
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,20 @@ def delete_dask_dashboard_ingress(cluster_name, workflow_id):
477477
plural="middlewares",
478478
name=f"replacepath-{workflow_id}",
479479
)
480+
481+
482+
def check_pod_by_prefix(pod_name_prefix, namespace="default"):
483+
"""Check if there is a Pod in the given namespace whose name starts with the specified prefix. We assume that there exists 0 or 1 pod with a given prefix."""
484+
try:
485+
pods = current_k8s_corev1_api_client.list_namespaced_pod(namespace=namespace)
486+
487+
for pod in pods.items:
488+
if pod.metadata.name.startswith(pod_name_prefix):
489+
if pod.status.phase == "Running":
490+
return "Running"
491+
else:
492+
return "Not Ready"
493+
494+
return "Not Found"
495+
except ApiException as e:
496+
return f"Error: {e.reason}"

reana_workflow_controller/rest/workflows.py

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from webargs import fields, validate
2323
from webargs.flaskparser import use_args, use_kwargs
2424
from reana_commons.config import WORKFLOW_TIME_FORMAT
25+
from reana_commons.utils import build_unique_component_name
2526
from reana_db.database import Session
2627
from reana_db.models import RunStatus, User, UserWorkflow, Workflow, WorkflowResource
2728
from reana_db.utils import (
@@ -48,6 +49,8 @@
4849
use_paginate_args,
4950
)
5051

52+
from reana_workflow_controller.k8s import check_pod_by_prefix
53+
5154
START = "start"
5255
STOP = "stop"
5356
DELETED = "deleted"
@@ -398,7 +401,20 @@ def get_workflows(args, paginate=None): # noqa
398401
if int_session:
399402
workflow_response["session_type"] = int_session.type_.name
400403
workflow_response["session_uri"] = int_session.path
404+
int_session_pod_name_prefix = build_unique_component_name(
405+
"run-session", int_session.workflow[0].id_
406+
)
407+
if int_session.status == RunStatus.created:
408+
pod_status = check_pod_by_prefix(
409+
pod_name_prefix=int_session_pod_name_prefix
410+
)
411+
if pod_status == "Running":
412+
int_session.status = RunStatus.running
413+
db_session = Session.object_session(int_session)
414+
db_session.commit()
415+
401416
workflow_response["session_status"] = int_session.status.name
417+
402418
# Skip workflow if type is interactive and there is no session
403419
elif type_ == "interactive":
404420
continue

0 commit comments

Comments
 (0)