feat: add endpoints for task cancellation and dispatcher control

This commit is contained in:
MayaTheShy
2026-03-22 11:43:09 -04:00
parent 3e55d77592
commit ad0754113d

View File

@@ -1092,6 +1092,31 @@ app.post('/api/tasks/:taskId/complete', (req, res) => {
}
});
// Cancel a running task (stops turtle + marks cancelled)
app.post('/api/tasks/:taskId/cancel', (req, res) => {
try {
const taskId = parseInt(req.params.taskId);
taskDispatcher.cancelTask(taskId);
res.json({ success: true });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// ========== TASK DISPATCHER ENDPOINTS ==========
// Get dispatcher status
app.get('/api/dispatcher/status', (req, res) => {
res.json(taskDispatcher.status());
});
// Enable/disable auto-dispatch
app.post('/api/dispatcher/toggle', (req, res) => {
const { enabled } = req.body;
taskDispatcher.enabled = enabled !== undefined ? enabled : !taskDispatcher.enabled;
res.json({ enabled: taskDispatcher.enabled });
});
// ========== MINING AREA ENDPOINTS ==========
// Helper to format mining area for API response
@@ -1943,6 +1968,7 @@ app.get('/api/integration/storage-status', async (req, res) => {
// Graceful shutdown
process.on('SIGINT', () => {
console.log('\n🛑 Shutting down server...');
taskDispatcher.stop();
db.closeDatabase();
process.exit(0);
});