From ad0754113de9830cd4b4254407af79a87c024e67 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 11:43:09 -0400 Subject: [PATCH] feat: add endpoints for task cancellation and dispatcher control --- server/server.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/server.js b/server/server.js index 75c5e94..c96af11 100644 --- a/server/server.js +++ b/server/server.js @@ -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); });