浏览代码

禁用bull

lrf 1 年之前
父节点
当前提交
c083d5fc88
共有 3 个文件被更改,包括 41 次插入28 次删除
  1. 1 2
      src/configuration.ts
  2. 13 0
      src/controller/file.controller.ts
  3. 27 26
      src/queue/FileClear.queue.ts

+ 1 - 2
src/configuration.ts

@@ -10,7 +10,6 @@ import { ServiceError, FrameworkErrorEnum } from './error/service.error';
 import { IMidwayContainer, Inject, MidwayConfigService } from '@midwayjs/core';
 import * as upload from '@midwayjs/upload';
 import { UseFile } from './entity/useFile.entity';
-import * as bull from '@midwayjs/bull';
 
 
 const axiosResponse = response => {
@@ -33,7 +32,7 @@ const axiosError = error => {
  */
 @Configuration({
   namespace: 'free',
-  imports: [koa, typegoose, axios, upload, bull],
+  imports: [koa, typegoose, axios, upload],
   importConfigs: [
     {
       default: DefaultConfig,

+ 13 - 0
src/controller/file.controller.ts

@@ -61,4 +61,17 @@ export class FileController {
     this.ctx.body = createReadStream(realPath);
     this.ctx.response.set('content-type', `/files/${getType(realPath)}`);
   }
+  @Post('/clear/files')
+  async clearFiles() {
+    try {
+      // 先重写文件地址表
+      const modelResults = this.fileService.scanModelHaveFile();
+      await this.fileService.setFileUriFromDefaultDataBase(modelResults);
+      // 再清除未使用的上传文件
+      await this.fileService.deleteNoUseFile();
+    } catch (error) {
+      console.error(error);
+    }
+    return 'ok';
+  }
 }

+ 27 - 26
src/queue/FileClear.queue.ts

@@ -1,28 +1,29 @@
-import { Processor, IProcessor } from '@midwayjs/bull';
-import { FORMAT, Inject } from '@midwayjs/core';
-import { FileService } from '../service/File.service';
+// 禁用bull
+// import { Processor, IProcessor } from '@midwayjs/bull';
+// import { FORMAT, Inject } from '@midwayjs/core';
+// import { FileService } from '../service/File.service';
 
-/**
- * 定时任务队列,处理未使用的文件
- */
-@Processor('FileClear', {
-  repeat: {
-    cron: FORMAT.CRONTAB.EVERY_DAY,
-  },
-})
-export class FileClearProcessor implements IProcessor {
-  @Inject()
-  fileService: FileService;
+// /**
+//  * 定时任务队列,处理未使用的文件
+//  */
+// @Processor('FileClear', {
+//   repeat: {
+//     cron: FORMAT.CRONTAB.EVERY_DAY,
+//   },
+// })
+// export class FileClearProcessor implements IProcessor {
+//   @Inject()
+//   fileService: FileService;
 
-  async execute() {
-    try {
-      // 先重写文件地址表
-      const modelResults = this.fileService.scanModelHaveFile();
-      await this.fileService.setFileUriFromDefaultDataBase(modelResults);
-      // 再清除未使用的上传文件
-      await this.fileService.deleteNoUseFile();
-    } catch (error) {
-      console.error(error);
-    }
-  }
-}
+//   async execute() {
+//     try {
+//       // 先重写文件地址表
+//       const modelResults = this.fileService.scanModelHaveFile();
+//       await this.fileService.setFileUriFromDefaultDataBase(modelResults);
+//       // 再清除未使用的上传文件
+//       await this.fileService.deleteNoUseFile();
+//     } catch (error) {
+//       console.error(error);
+//     }
+//   }
+// }