From 7849ee02568a91b63753c6c75b8d5a13eb2687dd Mon Sep 17 00:00:00 2001 From: Kelly Date: Sat, 13 Dec 2025 01:33:09 -0700 Subject: [PATCH] feat: Add POST /api/tasks/fix-null-methods endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates null method tasks to 'http' for proper worker qualification 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/src/routes/tasks.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/backend/src/routes/tasks.ts b/backend/src/routes/tasks.ts index fc2a6762..b3993287 100644 --- a/backend/src/routes/tasks.ts +++ b/backend/src/routes/tasks.ts @@ -891,6 +891,35 @@ router.post('/retry-failed', async (req: Request, res: Response) => { } }); +/** + * POST /api/tasks/fix-null-methods + * Update tasks with method=null to method='http' + * Ensures only HTTP-preflight workers can claim crawl tasks + */ +router.post('/fix-null-methods', async (_req: Request, res: Response) => { + try { + const { rows } = await pool.query(` + UPDATE worker_tasks + SET method = 'http', updated_at = NOW() + WHERE method IS NULL + AND role IN ('product_discovery', 'product_refresh', 'entry_point_discovery', 'store_discovery', 'payload_fetch') + AND status IN ('pending', 'failed') + RETURNING id, role, status + `); + + console.log(`[Tasks] Fixed ${rows.length} tasks with null method → http`); + + res.json({ + success: true, + tasks_fixed: rows.length, + tasks: rows.slice(0, 20), + }); + } catch (error: unknown) { + console.error('Error fixing null methods:', error); + res.status(500).json({ error: 'Failed to fix null methods' }); + } +}); + /** * GET /api/tasks/role/:role/last-completion * Get the last completion time for a role