Quellcode durchsuchen

refine crons controller

Signed-off-by: Gitea <zizhao.chen@zilliz.com>
Gitea vor 3 Jahren
Ursprung
Commit
e2272a015b

+ 1 - 0
client/src/context/WebSocket.tsx

@@ -32,6 +32,7 @@ export const WebSocketProvider = (props: { children: React.ReactNode }) => {
      * After all collections are not loading or building index, tell server stop pulling data.
      */
     socket.on(WS_EVENTS.COLLECTION, (data: any) => {
+      console.log(data);
       const collections: CollectionHttp[] = data.map(
         (v: any) => new CollectionHttp(v)
       );

+ 2 - 0
client/src/pages/collections/Collections.tsx

@@ -139,6 +139,8 @@ const Collections = () => {
       const hasLoadingOrBuildingCollection = res.some(
         v => checkLoading(v) || checkIndexBuilding(v)
       );
+      console.log(hasLoadingOrBuildingCollection);
+
       // if some collection is building index or loading, start pulling data
       if (hasLoadingOrBuildingCollection) {
         MilvusHttp.triggerCron({

+ 3 - 3
express/src/collections/collections.controller.ts

@@ -11,8 +11,8 @@ import {
 } from "./dto";
 
 export class CollectionController {
-  public collectionsService: CollectionsService;
-  public router: Router;
+  private collectionsService: CollectionsService;
+  private router: Router;
 
   constructor() {
     this.collectionsService = new CollectionsService(milvusService);
@@ -66,7 +66,7 @@ export class CollectionController {
 
     this.router.put("/:name/release", this.releaseCollection.bind(this));
 
-    this.router.put(
+    this.router.post(
       "/:name/insert",
       dtoValidationMiddleware(InsertDataDto),
       this.insert.bind(this)

+ 1 - 24
express/src/collections/dto.ts

@@ -23,9 +23,6 @@ enum VectorTypes {
 
 export class CreateCollectionDto {
   @IsString()
-  @IsNotEmpty({
-    message: "collection_name is empty",
-  })
   readonly collection_name: string;
 
   @IsBoolean()
@@ -34,9 +31,6 @@ export class CreateCollectionDto {
 
   @IsArray()
   @ArrayNotEmpty()
-  @IsNotEmpty({
-    message: "fields is required",
-  })
   readonly fields: FieldType[];
 }
 
@@ -50,17 +44,12 @@ export class InsertDataDto {
   @IsOptional()
   readonly partition_names?: string[];
 
-  @IsNotEmpty({
-    message: "fields_data is requried",
-  })
+  @IsArray()
   readonly fields_data: any[];
 }
 
 export class VectorSearchDto {
   @IsString()
-  @IsNotEmpty({
-    message: "collection_name is requried",
-  })
   collection_name: string;
 
   @IsOptional()
@@ -71,16 +60,10 @@ export class VectorSearchDto {
   expr?: string;
 
   @IsObject()
-  @IsNotEmpty({
-    message: "search_params is requried",
-  })
   search_params: SearchParam;
 
   @IsArray()
   @ArrayMinSize(1)
-  @IsNotEmpty({
-    message: "vectors is requried",
-  })
   vectors: number[][];
 
   @IsArray()
@@ -88,16 +71,10 @@ export class VectorSearchDto {
   output_fields?: string[];
 
   @IsEnum(VectorTypes, { message: "Type allow all->0 inmemory->1" })
-  @IsNotEmpty({
-    message: "vector_type is requried",
-  })
   vector_type: DataType.BinaryVector | DataType.FloatVector;
 }
 
 export class CreateAliasDto {
   @IsString()
-  @IsNotEmpty({
-    message: "alias is required",
-  })
   alias: string;
 }

+ 40 - 0
express/src/crons/crons.controller.ts

@@ -0,0 +1,40 @@
+import { NextFunction, Request, Response, Router } from "express";
+import { dtoValidationMiddleware } from "../middlewares/validation";
+import { CronsService, SchedulerRegistry } from "./crons.service";
+import { collectionsService } from "../collections";
+import { toggleCronJobByNameDto } from "./dto";
+
+export class CronsController {
+  private router: Router;
+  private schedulerRegistry: SchedulerRegistry;
+  private cronsService: CronsService;
+
+  constructor() {
+    this.schedulerRegistry = new SchedulerRegistry([]);
+    this.cronsService = new CronsService(
+      collectionsService,
+      this.schedulerRegistry
+    );
+    this.router = Router();
+  }
+
+  generateRoutes() {
+    this.router.put(
+      "/",
+      dtoValidationMiddleware(toggleCronJobByNameDto),
+      this.toggleCronJobByName.bind(this)
+    );
+
+    return this.router;
+  }
+
+  async toggleCronJobByName(req: Request, res: Response, next: NextFunction) {
+    const cronData = req.body;
+    try {
+      const result = await this.cronsService.toggleCronJobByName(cronData);
+      res.send(result);
+    } catch (error) {
+      next(error);
+    }
+  }
+}

+ 10 - 0
express/src/crons/dto.ts

@@ -0,0 +1,10 @@
+import { IsEnum, IsString } from "class-validator";
+import { WS_EVENTS_TYPE } from "../utils/Const";
+
+export class toggleCronJobByNameDto {
+  @IsString()
+  name: string;
+
+  @IsEnum(WS_EVENTS_TYPE, { message: "Type allow start->0 stop->1" })
+  type: WS_EVENTS_TYPE;
+}

+ 3 - 18
express/src/crons/index.ts

@@ -1,21 +1,6 @@
-import express from "express";
-import { CronsService, SchedulerRegistry } from "./crons.service";
-import { collectionsService } from "../collections";
+import { CronsController } from "./crons.controller";
 
-const router = express.Router();
-
-const schedulerRegistry = new SchedulerRegistry([]);
-
-const cronsService = new CronsService(collectionsService, schedulerRegistry);
-
-router.put("/", async (req, res, next) => {
-  const cronData = req.body;
-  try {
-    const result = await cronsService.toggleCronJobByName(cronData);
-    res.send(result);
-  } catch (error) {
-    next(error);
-  }
-});
+const cronsManager = new CronsController();
+const router = cronsManager.generateRoutes();
 
 export { router };