@@ -2,6 +2,7 @@ import { PrometheusQueryResponse } from "@/types/types";
22import { NextResponse } from "next/server" ;
33import { PrometheusDriver } from "prometheus-query" ;
44import { env } from "process" ;
5+ import { fetchSlurmData } from "@/lib/slurm-api" ;
56
67export const revalidate = 0 ;
78const PROMETHEUS_URL = env . PROMETHEUS_URL ;
@@ -38,26 +39,26 @@ async function getClusterNodes(): Promise<string[]> {
3839 }
3940
4041 try {
41- // Fetch node information from Slurm API
42- const baseURL = env . NEXT_PUBLIC_BASE_URL || "http://localhost:3000" ;
43- const response = await fetch ( `${ baseURL } /api/slurm/nodes` ) ;
42+ // Fetch node information directly from Slurm API
43+ const { data, error } = await fetchSlurmData ( '/nodes' ) ;
4444
45- if ( ! response . ok ) {
46- throw new Error ( `Failed to fetch nodes: ${ response . statusText } ` ) ;
45+ if ( error ) {
46+ console . error ( `Failed to fetch nodes from Slurm: ${ error } ` ) ;
47+ return clusterNodesCache . nodes ; // Return stale cache if available
4748 }
4849
49- const data = await response . json ( ) ;
50-
51- if ( ! data . nodes || ! Array . isArray ( data . nodes ) ) {
50+ if ( ! data ?. nodes || ! Array . isArray ( data . nodes ) ) {
5251 console . warn ( "Invalid nodes data format from Slurm API" ) ;
53- return [ ] ;
52+ return clusterNodesCache . nodes ; // Return stale cache if available
5453 }
5554
5655 // Extract node names
5756 const nodeNames = data . nodes
5857 . map ( ( node : any ) => node . name || null )
5958 . filter ( Boolean ) ;
6059
60+ console . log ( `Fetched ${ nodeNames . length } nodes from Slurm API` ) ;
61+
6162 // Update cache
6263 clusterNodesCache = {
6364 timestamp : now ,
@@ -67,7 +68,7 @@ async function getClusterNodes(): Promise<string[]> {
6768 return nodeNames ;
6869 } catch ( error ) {
6970 console . error ( "Error fetching cluster nodes:" , error ) ;
70- return [ ] ;
71+ return clusterNodesCache . nodes ; // Return stale cache if available
7172 }
7273}
7374
0 commit comments