Browse Source

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

chenshilong 7 years ago
parent
commit
b1fae1c291
5 changed files with 61 additions and 5 deletions
  1. 1 1
      Dockerfile
  2. 1 1
      Dockerfile_qa
  3. 1 1
      config/config.js
  4. 29 2
      server.js
  5. 29 0
      test/unit/reports/chk_file_time.js

+ 1 - 1
Dockerfile

@@ -2,7 +2,7 @@ FROM costbase:latest
 
 WORKDIR /home/ConstructionCost
 
-RUN git pull http://192.168.1.12:3000/SmartCost/ConstructionCost 1.0.0_online
+COPY . /home/ConstructionCost
 
 RUN cnpm install
 

+ 1 - 1
Dockerfile_qa

@@ -2,7 +2,7 @@ FROM costbase:latest
 
 WORKDIR /home/ConstructionCost
 
-RUN git pull http://192.168.1.12:3000/SmartCost/ConstructionCost 1.0.0_online
+COPY . /home/ConstructionCost
 
 RUN cnpm install
 

+ 1 - 1
config/config.js

@@ -31,7 +31,7 @@ module.exports = {
     pp:{server: "172.18.111.228", port: "27017"},
     prod:{
         dbURL:"mongodb://smartcost:SmartCost3850888@dds-wz9da4d5ca0fdd341.mongodb.rds.aliyuncs.com:3717,dds-wz9da4d5ca0fdd342.mongodb.rds.aliyuncs.com:3717/scConstruct?authSource=admin;replicaSet=mgset-7518601",
-        LicenseKey:"civil.smartcost.com.cn,834986144349993#A0XNdYDO9QzM8IiOiQWSiwSflNHbhZmOiI7ckJye0ICbuFkI1pjIEJCLi4TPnNnMEVXS4RGejhFZkNVMZZHTvVTWBZlcsNTaiZFbKJ HSklmM8cENUJTTnJUN9NGZTVTdrU4LmVHeudDcwtySsNWW5s4UPdVZVRDe7ETNnNHduZnWwsmI0IyUiwSO4MTNwYDO5gTM0IicfJye35XX3JyMiZzZiojIDJCLiETMuYHIT pEIkFWZyB7UiojIOJyebpjIkJHUiwiIzUTNxkDMgQjM7ADOxAjMiojI4J7QiwiIuNmLt36YuQ7cvNGdyFWbz9CbpZXajJiOiMXbEJCLig1jlzahlDZmpnInmb1uk/avoDrlmvJilrKqmXrunfb tmD0jnLiOiEmTDJCLiMTO9kZNdQ"
+        LicenseKey:"civil.smartcost.com.cn,834986144349993#A0XNdYDO9QzM8IiOiQWSiwSflNHbhZmOiI7ckJye0ICbuFkI1pjIEJCLi4TPnNnMEVXS4RGejhFZkNVMZZHTvVTWBZlcsNTaiZFbKJHSklmM8cENUJTTnJUN9NGZTVTdrU4LmVHeudDcwtySsNWW5s4UPdVZVRDe7ETNnNHduZnWwsmI0IyUiwSO4MTNwYDO5gTM0IicfJye35XX3JyMiZzZiojIDJCLiETMuYHITpEIkFWZyB7UiojIOJyebpjIkJHUiwiIzUTNxkDMgQjM7ADOxAjMiojI4J7QiwiIuNmLt36YuQ7cvNGdyFWbz9CbpZXajJiOiMXbEJCLig1jlzahlDZmpnInmb1uk/avoDrlmvJilrKqmXrunfbtmD0jnLiOiEmTDJCLiMTO9kZNdQ"
     },
     redis_local:{server:'127.0.0.1',port:'6379',pwd:'smartCost'},
     redis_qa:{server:'192.168.1.184',port:'6379',pwd:'smartCost'},

+ 29 - 2
server.js

@@ -13,7 +13,7 @@ let DBStore = require('connect-mongo')(session);
 let fs = require('fs');
 
 let URL = require('url');
-
+let cron = require('node-schedule');
 
 dbm.connect(process.env.NODE_ENV);
 //这里现在只引入了定额工料机里的models,当其它模块的models修改后使用:./modules/**/models/*.js引入所有的模块
@@ -116,4 +116,31 @@ app.listen(6060, function(){
     console.log('server started!');
 });
 
-
+//设置schedule job
+let rule = new cron.RecurrenceRule();
+//1. 每天凌晨3点一刻,删除临时文件
+rule.dayOfWeek = [1,2,3,4,5,6,0];
+rule.hour = 3;
+rule.minute = 15;
+cron.scheduleJob(rule, function(){
+    let path = __dirname + "/tmp";
+    fs.exists(path, function (exists) {
+        if (exists) {
+            fs.readdir(path, function (err, files) {
+                let currentTime = (new Date()).valueOf();
+                let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5);
+                files.forEach(function(file,index){
+                    if (file.indexOf(".xlsx") === (file.length - 5) ||
+                        file.indexOf(".pdf") === (file.length - 4)) {
+                        let curPath = path + "/" + file;
+                        fs.stat(curPath,function(err,data){
+                            if (timeGap > data.mtime) {
+                                fs.unlink(curPath);
+                            }
+                        });
+                    }
+                });
+            })
+        }
+    })
+});

+ 29 - 0
test/unit/reports/chk_file_time.js

@@ -0,0 +1,29 @@
+/**
+ * Created by Tony on 2018/7/25.
+ */
+
+let fs = require('fs');
+
+// let files = [];
+let path = "D:/GitHome/ConstructionCost/tmp";
+fs.exists(path, function (exists) {
+    if (exists) {
+        fs.readdir(path, function (err, files) {
+            let currentTime = (new Date()).valueOf();
+            let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5);
+            files.forEach(function(file,index){
+                if (file.indexOf(".xlsx") === (file.length - 5) ||
+                    file.indexOf(".pdf") === (file.length - 4)) {
+                    let curPath = path + "/" + file;
+                    fs.stat(curPath,function(err,data){
+                        //修改时间
+                        if (timeGap > data.mtime) {
+                            console.log(curPath + " will be deleted!");
+                            // fs.unlink(curPath);
+                        }
+                    });
+                }
+            });
+        })
+    }
+})