feature/framework #1
16
index.js
16
index.js
@@ -357,6 +357,22 @@ app.get('/api/cluster/members', async (req, res) => {
|
|||||||
// API endpoint to get task status
|
// API endpoint to get task status
|
||||||
app.get('/api/tasks/status', async (req, res) => {
|
app.get('/api/tasks/status', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const { ip } = req.query;
|
||||||
|
|
||||||
|
if (ip) {
|
||||||
|
try {
|
||||||
|
const nodeClient = new SporeApiClient(`http://${ip}`);
|
||||||
|
const taskStatus = await nodeClient.getTaskStatus();
|
||||||
|
return res.json(taskStatus);
|
||||||
|
} catch (innerError) {
|
||||||
|
console.error('Error fetching task status from specific node:', innerError);
|
||||||
|
return res.status(500).json({
|
||||||
|
error: 'Failed to fetch task status from node',
|
||||||
|
message: innerError.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!sporeClient) {
|
if (!sporeClient) {
|
||||||
return res.status(503).json({
|
return res.status(503).json({
|
||||||
error: 'Service unavailable',
|
error: 'Service unavailable',
|
||||||
|
|||||||
@@ -85,9 +85,12 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTasksStatus() {
|
async getTasksStatus(ip) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${this.baseUrl}/api/tasks/status`, {
|
const url = ip
|
||||||
|
? `${this.baseUrl}/api/tasks/status?ip=${encodeURIComponent(ip)}`
|
||||||
|
: `${this.baseUrl}/api/tasks/status`;
|
||||||
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
|
|||||||
@@ -249,7 +249,8 @@ class NodeDetailsViewModel extends ViewModel {
|
|||||||
// Load tasks data with state preservation
|
// Load tasks data with state preservation
|
||||||
async loadTasksData() {
|
async loadTasksData() {
|
||||||
try {
|
try {
|
||||||
const response = await window.apiClient.getTasksStatus();
|
const ip = this.get('nodeIp');
|
||||||
|
const response = await window.apiClient.getTasksStatus(ip);
|
||||||
this.set('tasks', response || []);
|
this.set('tasks', response || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load tasks:', error);
|
console.error('Failed to load tasks:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user