904118851 8 months ago
parent
commit
6aea02bb40

+ 4 - 1
1_FILTER_FACTORY/FILTER_FACTORY.js

@@ -1,3 +1,4 @@
+const process = require('process');
 const CMD = {}
 const time_count = 300;
 const redis_help = require('../src/use_redis');
@@ -182,5 +183,7 @@ function parsePromotionItem(item){
     }
     return null
 }
+CMD.init()
+process.on('message', ()=>{
 
-CMD.init()
+});

+ 6 - 1
2_PRODUCT_FACTORY/PRODUCT_FACTORY.js

@@ -1,3 +1,4 @@
+const process = require('process');
 const CMD = {}
 const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
 const filter_data_controllers = require('../src/data_manager/Controllers/filter_data_controllers');
@@ -39,7 +40,7 @@ async function processTask(){
                 let fq_book_result = await get_fq_book_tab_controllers.getData({ book_id: result.data.book_id });
                 if(fq_book_result.success){//如果番茄书库里有这本书
     
-                    result.data.genre = CMD.getFqGenre(fq_book_result.data.info.genre)
+                    result.data.genre = fq_book_result.data.info.genre
                     result.data.book_id = fq_book_result.data.book_id
                     result.data.book_name = fq_book_result.data.info.book_name
                     result.data.words = fq_book_result.data.info.word_number
@@ -350,4 +351,8 @@ CMD.update_video_applet_product = function(data){
         })
 }
 
+// process.on('message', ()=>{
+
+// });
+
 CMD.init()

+ 5 - 0
7_CHECK_AND_CREATE_URL_FACTORY/log/node-app.stdout.log

@@ -1,4 +1,5 @@
 <<<<<<< HEAD
+<<<<<<< HEAD
 2024-11-30 11:43:17: send_data_server:sql_task_help
 2024-11-30 11:43:17: Connected to the MySQL server.
 2024-11-30 11:43:19: sql: []
@@ -163906,3 +163907,7 @@
 >>>>>>> 806549b58fb6234e7a0f41405e1177d1d2a613a3
 2024-12-05 14:44:50: send_data_server:sql_task_help
 2024-12-05 14:44:50: Connected to the MySQL server.
+=======
+2024-12-05 15:30:30: send_data_server:sql_task_help
+2024-12-05 15:30:30: Connected to the MySQL server.
+>>>>>>> eae3bc01c5b7f475bfac43cc245bf9221eeb0238

+ 26 - 0
7_CHECK_AND_CREATE_URL_FACTORY/nohup.out

@@ -100,6 +100,7 @@
 [PM2][WARN] Current process list is not synchronized with saved list. App start_novel differs. Type 'pm2 save' to synchronize.
 >>>>>>> 806549b58fb6234e7a0f41405e1177d1d2a613a3
 [PM2] cron restart at 1 0 * * *
+<<<<<<< HEAD
 [PM2] Applying action restartProcessId on app [7_CHECK_AND_CREATE_URL_FACTORY](ids: [ 0 ])
 [PM2] [7_CHECK_AND_CREATE_URL_FACTORY](0) ✓
 ┌────┬───────────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
@@ -110,3 +111,28 @@
 │ 2  │ tg_factory                        │ default     │ N/A     │ fork    │ 0        │ 0      │ 44   │ stopped   │ 0%       │ 0b       │ root     │ disabled │
 └────┴───────────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
 [PM2][WARN] Current process list is not synchronized with saved list. App start_data differs. Type 'pm2 save' to synchronize.
+=======
+[PM2] Applying action restartProcessId on app [7_CHECK_AND_CREATE_URL_FACTORY](ids: [ 20 ])
+[PM2] [7_CHECK_AND_CREATE_URL_FACTORY](20) ✓
+┌────┬───────────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
+│ id │ name                              │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
+├────┼───────────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
+│ 20 │ 7_CHECK_AND_CREATE_URL_FACTORY    │ default     │ N/A     │ fork    │ 7373     │ 0s     │ 5    │ online    │ 0%       │ 9.6mb    │ root     │ disabled │
+│ 21 │ MESSAGE_DISPATCH                  │ default     │ N/A     │ fork    │ 7324     │ 19s    │ 10   │ online    │ 0%       │ 49.0mb   │ root     │ disabled │
+│ 23 │ start                             │ default     │ 1.0.0   │ fork    │ 17580    │ 29h    │ 0    │ online    │ 0%       │ 33.4mb   │ root     │ disabled │
+│ 22 │ tg_factory                        │ default     │ N/A     │ fork    │ 0        │ 0      │ 592  │ stopped   │ 0%       │ 0b       │ root     │ disabled │
+└────┴───────────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
+[PM2][WARN] Current process list is not synchronized with saved list. App start_novel differs. Type 'pm2 save' to synchronize.
+[PM2] cron restart at 1 0 * * *
+[PM2] Applying action restartProcessId on app [7_CHECK_AND_CREATE_URL_FACTORY](ids: [ 20 ])
+[PM2] [7_CHECK_AND_CREATE_URL_FACTORY](20) ✓
+┌────┬───────────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
+│ id │ name                              │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
+├────┼───────────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
+│ 20 │ 7_CHECK_AND_CREATE_URL_FACTORY    │ default     │ N/A     │ fork    │ 7603     │ 0s     │ 5    │ online    │ 0%       │ 5.6mb    │ root     │ disabled │
+│ 21 │ MESSAGE_DISPATCH                  │ default     │ N/A     │ fork    │ 7577     │ 7s     │ 10   │ online    │ 0%       │ 88.2mb   │ root     │ disabled │
+│ 23 │ start                             │ default     │ 1.0.0   │ fork    │ 17580    │ 29h    │ 0    │ online    │ 0%       │ 34.7mb   │ root     │ disabled │
+│ 22 │ tg_factory                        │ default     │ N/A     │ fork    │ 0        │ 0      │ 592  │ stopped   │ 0%       │ 0b       │ root     │ disabled │
+└────┴───────────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
+[PM2][WARN] Current process list is not synchronized with saved list. App start_novel differs. Type 'pm2 save' to synchronize.
+>>>>>>> eae3bc01c5b7f475bfac43cc245bf9221eeb0238

+ 27 - 0
MESSAGE_DISPATCH/log/node-app.stdout.log

@@ -1,4 +1,5 @@
 <<<<<<< HEAD
+<<<<<<< HEAD
 2024-12-04 16:10:04: Received: pong
 2024-12-04 16:10:34: Received: pong
 2024-12-04 16:11:01: 登录成功
@@ -996,3 +997,29 @@
 2024-12-05 15:36:30: Received: pong
 2024-12-05 15:37:00: Received: pong
 2024-12-05 15:37:30: Received: pong
+=======
+2024-12-05 15:30:23: 运行 MESSAGE_DISPATCH
+2024-12-05 15:30:23: Connected to Redis
+2024-12-05 15:30:23: WebSocket connected
+2024-12-05 15:30:23: Received: {"cmd":"updateAppConfig"}
+2024-12-05 15:30:23: recvMessage: updateAppConfig
+2024-12-05 15:30:23: Received: {"cmd":"updateFilterConfig"}
+2024-12-05 15:30:23: recvMessage: updateFilterConfig
+2024-12-05 15:30:23: Received: {"cmd":"updateMainConfig"}
+2024-12-05 15:30:23: recvMessage: updateMainConfig
+2024-12-05 15:30:23: Received: {"cmd":"updatePlatformConfig"}
+2024-12-05 15:30:23: recvMessage: updatePlatformConfig
+2024-12-05 15:30:53: Received: pong
+2024-12-05 15:31:23: Received: pong
+2024-12-05 15:31:53: Received: pong
+2024-12-05 15:32:23: Received: pong
+2024-12-05 15:32:53: Received: pong
+2024-12-05 15:33:23: Received: pong
+2024-12-05 15:33:53: Received: pong
+2024-12-05 15:34:23: Received: pong
+2024-12-05 15:34:53: Received: pong
+2024-12-05 15:35:23: Received: pong
+2024-12-05 15:35:53: Received: pong
+2024-12-05 15:36:23: Received: pong
+2024-12-05 15:36:53: Received: pong
+>>>>>>> eae3bc01c5b7f475bfac43cc245bf9221eeb0238

File diff suppressed because it is too large
+ 0 - 0
MESSAGE_DISPATCH/nohup.out


+ 160 - 0
ProcessManager.js

@@ -0,0 +1,160 @@
+const { fork } = require('child_process');
+const path = require('path');
+
+class ProcessManager {
+    constructor() {
+        // 存储所有worker进程
+        this.workers = new Map();
+        
+        // 定义不同worker的配置
+        this.workerConfigs = [
+            {
+                name: '1_FILTER_FACTORY', //筛选数据
+                script: './1_FILTER_FACTORY/FILTER_FACTORY.js',
+                args: ['--type=data'],
+                restart: true  // 是否在崩溃时重启
+            },
+            {
+                name: '2_PRODUCT_FACTORY',//书库筛选
+                script: './2_PRODUCT_FACTORY/PRODUCT_FACTORY.js',
+                args: ['--type=data'],
+                restart: true
+            },
+            {
+                name: '5_CREATE_LINK_FACTORY', //创建推广连接
+                script: './5_CREATE_LINK_FACTORY/CREATE_LINK_FACTORY.js',
+                args: ['--type=data'],
+                restart: true
+            },
+            {
+                name: '7_CHECK_AND_CREATE_URL_FACTORY',//创建检测连接
+                script: './7_CHECK_AND_CREATE_URL_FACTORY/CHECK_AND_CREATE_URL_FACTORY.js',
+                args: ['--type=data'],
+                restart: true
+            },
+            {
+                name: 'MESSAGE_DISPATCH', //消息中心
+                script: './MESSAGE_DISPATCH/MESSAGE_DISPATCH.js',
+                args: ['--type=data'],
+                restart: true
+            },
+        ];
+    }
+
+    start() {
+        // 启动所有worker
+        this.workerConfigs.forEach(config => {
+            this.createWorker(config);
+        });
+
+        // 处理主进程的退出
+        process.on('SIGTERM', () => this.shutdown());
+        process.on('SIGINT', () => this.shutdown());
+    }
+
+    createWorker(config) {
+        const worker = fork(
+            path.join(__dirname, 'workers', config.script), 
+            config.args,
+            {
+                env: { ...process.env }  // 可以添加额外的环境变量
+            }
+        );
+
+        this.workers.set(config.name, {
+            process: worker,
+            config: config,
+            startTime: Date.now()
+        });
+
+        // 监听工作进程消息
+        worker.on('message', (message) => {
+            this.handleWorkerMessage(config.name, message);
+        });
+
+        // 监听错误
+        worker.on('error', (error) => {
+            console.error(`[${config.name}] 错误:`, error);
+        });
+
+        // 监听退出
+        worker.on('exit', (code, signal) => {
+            console.log(`[${config.name}] 退出,代码: ${code}, 信号: ${signal}`);
+            
+            // 从workers中移除
+            this.workers.delete(config.name);
+
+            // 如果配置了重启且不是正常关闭,则重新启动
+            if (config.restart && !this.isShuttingDown) {
+                console.log(`[${config.name}] 正在重启...`);
+                setTimeout(() => this.createWorker(config), 1000);
+            }
+        });
+
+        console.log(`[${config.name}] 已启动,PID: ${worker.pid}`);
+        return worker;
+    }
+
+    handleWorkerMessage(workerName, message) {
+        console.log(`[${workerName}] 消息:`, message);
+        
+        // 处理来自worker的不同类型消息
+        switch(message.type) {
+            case 'status':
+                this.updateWorkerStatus(workerName, message.data);
+                break;
+            case 'error':
+                this.handleWorkerError(workerName, message.data);
+                break;
+            // ... 其他消息类型
+        }
+    }
+
+    updateWorkerStatus(workerName, status) {
+        const worker = this.workers.get(workerName);
+        if (worker) {
+            worker.status = status;
+        }
+    }
+
+    handleWorkerError(workerName, error) {
+        console.error(`[${workerName}] 报告错误:`, error);
+        // 实现错误处理逻辑
+    }
+
+    getWorkerStatus(workerName) {
+        return this.workers.get(workerName);
+    }
+
+    async shutdown() {
+        this.isShuttingDown = true;
+        console.log('开始关闭所有工作进程...');
+
+        // 向所有worker发送关闭信号
+        const shutdownPromises = Array.from(this.workers.entries()).map(
+            async ([name, {process}]) => {
+                console.log(`正在关闭 ${name}...`);
+                process.send({ type: 'shutdown' });
+                
+                return new Promise((resolve) => {
+                    process.once('exit', resolve);
+                    
+                    // 设置超时强制结束
+                    setTimeout(() => {
+                        if (!process.killed) {
+                            console.log(`${name} 强制终止`);
+                            process.kill('SIGKILL');
+                        }
+                    }, 5000);
+                });
+            }
+        );
+
+        await Promise.all(shutdownPromises);
+        console.log('所有工作进程已关闭');
+        process.exit(0);
+    }
+}
+
+// 启动进程管理器
+module.exports =  ProcessManager;

+ 1 - 1
etc/config.json

@@ -1,5 +1,5 @@
 {
-    "isDebug":false,
+    "isDebug":true,
     "redis_config": {
         "host": "127.0.0.1",
         "port": 6379

File diff suppressed because it is too large
+ 12 - 0
logs/combined.log


File diff suppressed because it is too large
+ 172 - 0
logs/out.log


+ 6 - 1
tg_factory_main.js

@@ -1,9 +1,10 @@
 setInterval(() => {
 
 }, 15000);
+const ProcessManager = require('./ProcessManager');
 const helper = require('./src/helper');
 const HttpClient = require('./src/HttpClient');
-const redis_help = require('./src/use_redis');
+const redis_help = require('./src/use_redis'); 
 redis_help.connect( async (results)=>{
     if(results){
         main()
@@ -21,3 +22,7 @@ var main = function(){
     require("./1_FILTER_FACTORY/FILTER_FACTORY")
 }
 
+
+
+// const manager = new ProcessManager();
+// manager.start();

Some files were not shown because too many files changed in this diff