Spaces:
Sleeping
Sleeping
| import { Router } from 'express'; | |
| import { verifyToken } from './auth.js'; | |
| import { addJob, getQueueStatus } from '../lib/queue.js'; | |
| const router = Router(); | |
| /** | |
| * 压力测试接口:模拟大规模高并发请求进入队列 | |
| */ | |
| router.post('/stress-test', verifyToken, async (req: any, res) => { | |
| const { count = 10 } = req.body; | |
| const startTime = Date.now(); | |
| const tasks = []; | |
| for (let i = 0; i < count; i++) { | |
| tasks.push(addJob('ai_workflow', { | |
| workflowId: `stress-test-${i}`, | |
| workflow: { id: `w-${i}`, name: `Stress Test Workflow`, nodes: [], edges: [] }, | |
| input: `Mock Input ${i}` | |
| })); | |
| } | |
| try { | |
| await Promise.all(tasks); | |
| const duration = Date.now() - startTime; | |
| const status = await getQueueStatus(); | |
| res.json({ | |
| success: true, | |
| count, | |
| duration: `${duration}ms`, | |
| avgTime: `${duration / count}ms`, | |
| status | |
| }); | |
| } catch (err: any) { | |
| res.status(500).json({ success: false, error: err.message }); | |
| } | |
| }); | |
| /** | |
| * 获取队列当前详细状态 | |
| */ | |
| router.get('/queue-status', async (_req, res) => { | |
| const status = await getQueueStatus(); | |
| res.json(status); | |
| }); | |
| /** | |
| * 获取系统健康指标 | |
| */ | |
| router.get('/health-details', (req, res) => { | |
| res.json({ | |
| status: 'ok', | |
| engine: 'Qwen2.5-7B', | |
| provider: 'SiliconFlow', | |
| timestamp: new Date().toISOString() | |
| }); | |
| }); | |
| export default router; | |