From 7c536806bf8fe38cd6591fcf48a6f9a77d4a9045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=8A=E5=B9=B3?= <951984189@qq.com> Date: Mon, 8 Mar 2021 18:53:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- f.yml | 2 + package.json | 3 +- src/{resource => app/modules/base}/init.sql | 76 ---------------- src/app/modules/demo/config.ts | 16 ++++ src/app/modules/task/init.sql | 99 +++++++++++++++++++++ src/app/modules/task/queue/task.ts | 4 +- src/app/modules/task/service/info.ts | 4 +- src/app/public/uploads/说明.md | 1 - src/config/config.local.ts | 6 +- src/config/config.prod.ts | 6 +- 11 files changed, 130 insertions(+), 89 deletions(-) rename src/{resource => app/modules/base}/init.sql (92%) create mode 100644 src/app/modules/demo/config.ts create mode 100644 src/app/modules/task/init.sql delete mode 100644 src/app/public/uploads/说明.md diff --git a/.gitignore b/.gitignore index 3cee0bb..e73d493 100755 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ run/ .tsbuildinfo.* src/app/public/uploads/ typings/ -resource/.cache +.cache diff --git a/f.yml b/f.yml index 5c83602..dcbca2b 100644 --- a/f.yml +++ b/f.yml @@ -2,5 +2,7 @@ service: cool-admin ## 应用发布到云平台的名字,一般指应用名 provider: name: aliyun ## 发布的云平台,aliyun,tencent 等 + runtime: nodejs12 + memorySize: 512 deployType: egg ## 部署的应用类型 \ No newline at end of file diff --git a/package.json b/package.json index c74e506..ae00a58 100755 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "jsonwebtoken": "^8.5.1", "md5": "^2.3.0", "midwayjs-cool-alipay": "^1.0.1", - "midwayjs-cool-core": "^3.0.13", + "midwayjs-cool-core": "^3.0.15", "midwayjs-cool-oss": "^1.0.10", "midwayjs-cool-queue": "^1.0.3", "midwayjs-cool-redis": "^1.0.6", @@ -25,6 +25,7 @@ }, "devDependencies": { "@midwayjs/cli": "^1.2.41", + "@midwayjs/cli-plugin-faas": "^1.2.49", "@midwayjs/egg-ts-helper": "^1.0.5", "@midwayjs/luckyeye": "^1.0.2", "@midwayjs/mock": "^2.7.7", diff --git a/src/resource/init.sql b/src/app/modules/base/init.sql similarity index 92% rename from src/resource/init.sql rename to src/app/modules/base/init.sql index d9c88a3..bb81a4e 100644 --- a/src/resource/init.sql +++ b/src/app/modules/base/init.sql @@ -736,82 +736,6 @@ BEGIN; INSERT INTO `demo_app_goods` VALUES (1, '2021-03-02 17:22:10.687462', '2021-03-02 17:22:10.687462', 'cool-mall商城', 'https://docs.cool-js.com/mall/show05.jpeg', 20.00); COMMIT; --- ---------------------------- --- Table structure for task_info --- ---------------------------- -DROP TABLE IF EXISTS `task_info`; -CREATE TABLE `task_info` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', - `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', - `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', - `repeatConf` varchar(1000) DEFAULT NULL COMMENT '任务配置', - `name` varchar(255) NOT NULL COMMENT '名称', - `cron` varchar(255) DEFAULT NULL COMMENT 'cron', - `limitCount` int(11) DEFAULT NULL COMMENT '最大执行次数 不传为无限次', - `every` int(11) DEFAULT NULL COMMENT '每间隔多少毫秒执行一次 如果cron设置了 这项设置就无效', - `remark` varchar(255) DEFAULT NULL COMMENT '备注', - `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:停止 1:运行', - `startDate` datetime DEFAULT NULL COMMENT '开始时间', - `endDate` datetime DEFAULT NULL COMMENT '结束时间', - `data` varchar(255) DEFAULT NULL COMMENT '数据', - `service` varchar(255) DEFAULT NULL COMMENT '执行的service实例ID', - `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:系统 1:用户', - `nextRunTime` datetime DEFAULT NULL COMMENT '下一次执行时间', - `taskType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:cron 1:时间间隔', - `jobId` varchar(255) DEFAULT NULL COMMENT '任务ID', - PRIMARY KEY (`id`), - KEY `IDX_6ced02f467e59bd6306b549bb0` (`createTime`), - KEY `IDX_2adc6f9c241391126f27dac145` (`updateTime`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; --- ---------------------------- --- Records of task_info --- ---------------------------- -BEGIN; -INSERT INTO `task_info` VALUES (1, '2021-03-05 11:46:24.000000', '2021-03-05 16:33:44.081230', '{\"count\":1,\"id\":1,\"createTime\":\"2021-03-05 11:46:24\",\"updateTime\":\"2021-03-05 16:33:37\",\"jobId\":1,\"name\":\"测试\",\"every\":1000,\"status\":1,\"service\":\"demoOrderService.test()\",\"type\":\"0\",\"taskType\":1}', '测试', NULL, NULL, 1000, NULL, 0, NULL, NULL, NULL, 'demoOrderService.test()', 0, NULL, 1, 'repeat:73bac7c57dd4c1ffd6dc41c3c3cb40e1:1614932670000'); -COMMIT; - --- ---------------------------- --- Table structure for task_log --- ---------------------------- -DROP TABLE IF EXISTS `task_log`; -CREATE TABLE `task_log` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', - `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', - `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', - `taskId` bigint(20) DEFAULT NULL COMMENT '任务ID', - `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:失败 1:成功', - `detail` text COMMENT '详情描述', - PRIMARY KEY (`id`), - KEY `IDX_b9af0e100be034924b270aab31` (`createTime`), - KEY `IDX_8857d8d43d38bebd7159af1fa6` (`updateTime`), - KEY `IDX_1142dfec452e924b346f060fda` (`taskId`) -) ENGINE=InnoDB AUTO_INCREMENT=541 DEFAULT CHARSET=utf8mb4; - --- ---------------------------- --- Records of task_log --- ---------------------------- -BEGIN; -INSERT INTO `task_log` VALUES (521, '2021-03-05 16:32:09.017824', '2021-03-05 16:32:09.017824', 1, 1, ''); -INSERT INTO `task_log` VALUES (522, '2021-03-05 16:32:10.015478', '2021-03-05 16:32:10.015478', 1, 1, ''); -INSERT INTO `task_log` VALUES (523, '2021-03-05 16:32:11.017549', '2021-03-05 16:32:11.017549', 1, 1, ''); -INSERT INTO `task_log` VALUES (524, '2021-03-05 16:32:12.015647', '2021-03-05 16:32:12.015647', 1, 1, ''); -INSERT INTO `task_log` VALUES (525, '2021-03-05 16:32:35.349964', '2021-03-05 16:32:35.349964', 1, 1, ''); -INSERT INTO `task_log` VALUES (526, '2021-03-05 16:33:22.020797', '2021-03-05 16:33:22.020797', 1, 1, ''); -INSERT INTO `task_log` VALUES (527, '2021-03-05 16:33:23.015415', '2021-03-05 16:33:23.015415', 1, 1, ''); -INSERT INTO `task_log` VALUES (528, '2021-03-05 16:33:24.013962', '2021-03-05 16:33:24.013962', 1, 1, ''); -INSERT INTO `task_log` VALUES (529, '2021-03-05 16:33:29.017289', '2021-03-05 16:33:29.017289', 1, 1, ''); -INSERT INTO `task_log` VALUES (530, '2021-03-05 16:33:30.014388', '2021-03-05 16:33:30.014388', 1, 1, ''); -INSERT INTO `task_log` VALUES (531, '2021-03-05 16:33:31.019317', '2021-03-05 16:33:31.019317', 1, 1, ''); -INSERT INTO `task_log` VALUES (532, '2021-03-05 16:33:32.016401', '2021-03-05 16:33:32.016401', 1, 1, ''); -INSERT INTO `task_log` VALUES (533, '2021-03-05 16:33:33.014518', '2021-03-05 16:33:33.014518', 1, 1, ''); -INSERT INTO `task_log` VALUES (534, '2021-03-05 16:33:38.019010', '2021-03-05 16:33:38.019010', 1, 1, ''); -INSERT INTO `task_log` VALUES (535, '2021-03-05 16:33:39.015834', '2021-03-05 16:33:39.015834', 1, 1, ''); -INSERT INTO `task_log` VALUES (536, '2021-03-05 16:33:40.015489', '2021-03-05 16:33:40.015489', 1, 1, ''); -INSERT INTO `task_log` VALUES (537, '2021-03-05 16:33:41.013458', '2021-03-05 16:33:41.013458', 1, 1, ''); -INSERT INTO `task_log` VALUES (538, '2021-03-05 16:33:42.015814', '2021-03-05 16:33:42.015814', 1, 1, ''); -INSERT INTO `task_log` VALUES (539, '2021-03-05 16:33:43.014712', '2021-03-05 16:33:43.014712', 1, 1, ''); -INSERT INTO `task_log` VALUES (540, '2021-03-05 16:33:44.014487', '2021-03-05 16:33:44.014487', 1, 1, ''); -COMMIT; SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/app/modules/demo/config.ts b/src/app/modules/demo/config.ts new file mode 100644 index 0000000..5e35cf5 --- /dev/null +++ b/src/app/modules/demo/config.ts @@ -0,0 +1,16 @@ +import { Application } from 'egg'; +import { ModuleConfig } from 'midwayjs-cool-core'; + +/** + * 示例 + */ +export default (app: Application) => { + return { + // 模块名称 + name: '测试模块', + // 模块描述 + description: '演示示例', + // 中间件 + middlewares: [], + } as ModuleConfig; +}; \ No newline at end of file diff --git a/src/app/modules/task/init.sql b/src/app/modules/task/init.sql new file mode 100644 index 0000000..8fcd6f8 --- /dev/null +++ b/src/app/modules/task/init.sql @@ -0,0 +1,99 @@ +/* + Navicat Premium Data Transfer + + Source Server : localhost_3306 + Source Server Type : MySQL + Source Server Version : 50725 + Source Host : localhost:3306 + Source Schema : cool + + Target Server Type : MySQL + Target Server Version : 50725 + File Encoding : 65001 + + Date: 05/03/2021 16:41:26 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + + +-- ---------------------------- +-- Table structure for task_info +-- ---------------------------- +DROP TABLE IF EXISTS `task_info`; +CREATE TABLE `task_info` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', + `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', + `repeatConf` varchar(1000) DEFAULT NULL COMMENT '任务配置', + `name` varchar(255) NOT NULL COMMENT '名称', + `cron` varchar(255) DEFAULT NULL COMMENT 'cron', + `limitCount` int(11) DEFAULT NULL COMMENT '最大执行次数 不传为无限次', + `every` int(11) DEFAULT NULL COMMENT '每间隔多少毫秒执行一次 如果cron设置了 这项设置就无效', + `remark` varchar(255) DEFAULT NULL COMMENT '备注', + `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:停止 1:运行', + `startDate` datetime DEFAULT NULL COMMENT '开始时间', + `endDate` datetime DEFAULT NULL COMMENT '结束时间', + `data` varchar(255) DEFAULT NULL COMMENT '数据', + `service` varchar(255) DEFAULT NULL COMMENT '执行的service实例ID', + `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:系统 1:用户', + `nextRunTime` datetime DEFAULT NULL COMMENT '下一次执行时间', + `taskType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:cron 1:时间间隔', + `jobId` varchar(255) DEFAULT NULL COMMENT '任务ID', + PRIMARY KEY (`id`), + KEY `IDX_6ced02f467e59bd6306b549bb0` (`createTime`), + KEY `IDX_2adc6f9c241391126f27dac145` (`updateTime`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Records of task_info +-- ---------------------------- +BEGIN; +INSERT INTO `task_info` VALUES (1, '2021-03-05 11:46:24.000000', '2021-03-05 16:33:44.081230', '{\"count\":1,\"id\":1,\"createTime\":\"2021-03-05 11:46:24\",\"updateTime\":\"2021-03-05 16:33:37\",\"jobId\":1,\"name\":\"测试\",\"every\":1000,\"status\":1,\"service\":\"demoOrderService.test()\",\"type\":\"0\",\"taskType\":1}', '测试', NULL, NULL, 1000, NULL, 0, NULL, NULL, NULL, 'demoOrderService.test()', 0, NULL, 1, 'repeat:73bac7c57dd4c1ffd6dc41c3c3cb40e1:1614932670000'); +COMMIT; + +-- ---------------------------- +-- Table structure for task_log +-- ---------------------------- +DROP TABLE IF EXISTS `task_log`; +CREATE TABLE `task_log` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', + `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', + `taskId` bigint(20) DEFAULT NULL COMMENT '任务ID', + `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:失败 1:成功', + `detail` text COMMENT '详情描述', + PRIMARY KEY (`id`), + KEY `IDX_b9af0e100be034924b270aab31` (`createTime`), + KEY `IDX_8857d8d43d38bebd7159af1fa6` (`updateTime`), + KEY `IDX_1142dfec452e924b346f060fda` (`taskId`) +) ENGINE=InnoDB AUTO_INCREMENT=541 DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Records of task_log +-- ---------------------------- +BEGIN; +INSERT INTO `task_log` VALUES (521, '2021-03-05 16:32:09.017824', '2021-03-05 16:32:09.017824', 1, 1, ''); +INSERT INTO `task_log` VALUES (522, '2021-03-05 16:32:10.015478', '2021-03-05 16:32:10.015478', 1, 1, ''); +INSERT INTO `task_log` VALUES (523, '2021-03-05 16:32:11.017549', '2021-03-05 16:32:11.017549', 1, 1, ''); +INSERT INTO `task_log` VALUES (524, '2021-03-05 16:32:12.015647', '2021-03-05 16:32:12.015647', 1, 1, ''); +INSERT INTO `task_log` VALUES (525, '2021-03-05 16:32:35.349964', '2021-03-05 16:32:35.349964', 1, 1, ''); +INSERT INTO `task_log` VALUES (526, '2021-03-05 16:33:22.020797', '2021-03-05 16:33:22.020797', 1, 1, ''); +INSERT INTO `task_log` VALUES (527, '2021-03-05 16:33:23.015415', '2021-03-05 16:33:23.015415', 1, 1, ''); +INSERT INTO `task_log` VALUES (528, '2021-03-05 16:33:24.013962', '2021-03-05 16:33:24.013962', 1, 1, ''); +INSERT INTO `task_log` VALUES (529, '2021-03-05 16:33:29.017289', '2021-03-05 16:33:29.017289', 1, 1, ''); +INSERT INTO `task_log` VALUES (530, '2021-03-05 16:33:30.014388', '2021-03-05 16:33:30.014388', 1, 1, ''); +INSERT INTO `task_log` VALUES (531, '2021-03-05 16:33:31.019317', '2021-03-05 16:33:31.019317', 1, 1, ''); +INSERT INTO `task_log` VALUES (532, '2021-03-05 16:33:32.016401', '2021-03-05 16:33:32.016401', 1, 1, ''); +INSERT INTO `task_log` VALUES (533, '2021-03-05 16:33:33.014518', '2021-03-05 16:33:33.014518', 1, 1, ''); +INSERT INTO `task_log` VALUES (534, '2021-03-05 16:33:38.019010', '2021-03-05 16:33:38.019010', 1, 1, ''); +INSERT INTO `task_log` VALUES (535, '2021-03-05 16:33:39.015834', '2021-03-05 16:33:39.015834', 1, 1, ''); +INSERT INTO `task_log` VALUES (536, '2021-03-05 16:33:40.015489', '2021-03-05 16:33:40.015489', 1, 1, ''); +INSERT INTO `task_log` VALUES (537, '2021-03-05 16:33:41.013458', '2021-03-05 16:33:41.013458', 1, 1, ''); +INSERT INTO `task_log` VALUES (538, '2021-03-05 16:33:42.015814', '2021-03-05 16:33:42.015814', 1, 1, ''); +INSERT INTO `task_log` VALUES (539, '2021-03-05 16:33:43.014712', '2021-03-05 16:33:43.014712', 1, 1, ''); +INSERT INTO `task_log` VALUES (540, '2021-03-05 16:33:44.014487', '2021-03-05 16:33:44.014487', 1, 1, ''); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/src/app/modules/task/queue/task.ts b/src/app/modules/task/queue/task.ts index 8a1a4ff..2ce7740 100644 --- a/src/app/modules/task/queue/task.ts +++ b/src/app/modules/task/queue/task.ts @@ -18,8 +18,8 @@ export abstract class TaskInfoQueue implements ICoolQueue { async data(job: any, done: any): Promise { try { console.log('收到的数据', job.data); - this.taskInfoService.invokeService(job.data.service); - this.taskInfoService.record(job.data, 1); + const result = await this.taskInfoService.invokeService(job.data.service); + this.taskInfoService.record(job.data, 1, JSON.stringify(result)); } catch (error) { this.taskInfoService.record(job.data, 0, error); } diff --git a/src/app/modules/task/service/info.ts b/src/app/modules/task/service/info.ts index 6e95c02..2f65797 100644 --- a/src/app/modules/task/service/info.ts +++ b/src/app/modules/task/service/info.ts @@ -295,9 +295,9 @@ export class TaskInfoService extends BaseService { const lastArr = child.split('('); const param = lastArr[1].replace(')', ''); if (!param) { - service[lastArr[0]](); + return service[lastArr[0]](); } else { - service[lastArr[0]](JSON.parse(param)); + return service[lastArr[0]](JSON.parse(param)); } } } diff --git a/src/app/public/uploads/说明.md b/src/app/public/uploads/说明.md deleted file mode 100644 index c741e12..0000000 --- a/src/app/public/uploads/说明.md +++ /dev/null @@ -1 +0,0 @@ -文件上传路径 \ No newline at end of file diff --git a/src/config/config.local.ts b/src/config/config.local.ts index c37f1ee..768ffe3 100644 --- a/src/config/config.local.ts +++ b/src/config/config.local.ts @@ -7,11 +7,11 @@ export default (appInfo: EggAppInfo) => { config.orm = { type: 'mysql', - host: '127.0.0.1', + host: '139.196.196.203', port: 3306, - username: 'root', + username: 'cooladmin', password: '123123', - database: 'cool', + database: 'cooladmin', // 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失 synchronize: true, // 打印日志 diff --git a/src/config/config.prod.ts b/src/config/config.prod.ts index 4ce3e10..c3ef4e3 100644 --- a/src/config/config.prod.ts +++ b/src/config/config.prod.ts @@ -7,11 +7,11 @@ export default (appInfo: EggAppInfo) => { config.orm = { type: 'mysql', - host: '127.0.0.1', + host: '139.196.196.203', port: 3306, - username: 'root', + username: 'cooladmin', password: '123123', - database: 'cool-admin-next', + database: 'cooladmin', // 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失 synchronize: false, // 打印日志