Explorar el Código

添加 StartTaskSendBody 接口,更新任务服务的批处理大小至 50,优化任务路由导入,增强代码整洁性。

wuyi hace 1 mes
padre
commit
eaf4f162b3
Se han modificado 3 ficheros con 7 adiciones y 7 borrados
  1. 5 0
      src/dto/task.dto.ts
  2. 1 5
      src/routes/task.routes.ts
  3. 1 2
      src/services/task.service.ts

+ 5 - 0
src/dto/task.dto.ts

@@ -62,3 +62,8 @@ export interface InviteMembersBody {
   accessHash?: string
   accessHash?: string
   members: string[]
   members: string[]
 }
 }
+
+export interface StartTaskSendBody {
+  taskId: number
+  senderSendLimit?: number
+}

+ 1 - 5
src/routes/task.routes.ts

@@ -1,11 +1,7 @@
 import { FastifyInstance } from 'fastify'
 import { FastifyInstance } from 'fastify'
 import { TaskController } from '../controllers/task.controller'
 import { TaskController } from '../controllers/task.controller'
 import { hasRole } from '../middlewares/auth.middleware'
 import { hasRole } from '../middlewares/auth.middleware'
-import {
-  UpdateTaskBody,
-  ListTaskQuery,
-  ListTaskItemQuery
-} from '../dto/task.dto'
+import { UpdateTaskBody, ListTaskQuery, ListTaskItemQuery } from '../dto/task.dto'
 import { UserRole } from '../entities/user.entity'
 import { UserRole } from '../entities/user.entity'
 
 
 export default async function taskRoutes(fastify: FastifyInstance) {
 export default async function taskRoutes(fastify: FastifyInstance) {

+ 1 - 2
src/services/task.service.ts

@@ -23,7 +23,7 @@ export class TaskService {
   private senderCursor = 0
   private senderCursor = 0
   private senderCache: Sender[] = []
   private senderCache: Sender[] = []
   private readonly pollIntervalMs = 5000
   private readonly pollIntervalMs = 5000
-  private readonly taskBatchSize = 20
+  private readonly taskBatchSize = 50
   private readonly instanceId = `${process.pid}-${Math.random().toString(36).slice(2, 8)}`
   private readonly instanceId = `${process.pid}-${Math.random().toString(36).slice(2, 8)}`
 
 
   constructor(app: FastifyInstance) {
   constructor(app: FastifyInstance) {
@@ -252,7 +252,6 @@ export class TaskService {
       await this.taskRepository.increment({ id: task.id }, 'successCount', batchSuccess)
       await this.taskRepository.increment({ id: task.id }, 'successCount', batchSuccess)
     }
     }
 
 
-    // 如果未跑完整个批次,说明中途被暂停/停止,直接返回
     if (batchSent < pendingItems.length) {
     if (batchSent < pendingItems.length) {
       return
       return
     }
     }