Authored by xuqi

flush cdn

@@ -11,6 +11,7 @@ import sh from 'shelljs'; @@ -11,6 +11,7 @@ import sh from 'shelljs';
11 import ssh from 'ssh2'; 11 import ssh from 'ssh2';
12 import fs from 'fs'; 12 import fs from 'fs';
13 import path from 'path'; 13 import path from 'path';
  14 +import rp from 'request-promise';
14 15
15 import config from '../../config/config'; 16 import config from '../../config/config';
16 import ws from '../../lib/ws'; 17 import ws from '../../lib/ws';
@@ -31,6 +32,11 @@ class Deploy { @@ -31,6 +32,11 @@ class Deploy {
31 32
32 return this._deploy().then(() => { 33 return this._deploy().then(() => {
33 self._state('deploying'); 34 self._state('deploying');
  35 + }).then(() => {
  36 + self._flush();
  37 + self._state('flushing');
  38 + }).then(() => {
  39 + self._state('deploy success');
34 }).catch(e => { 40 }).catch(e => {
35 console.error(e); 41 console.error(e);
36 self._state('fail'); 42 self._state('fail');
@@ -59,13 +65,25 @@ class Deploy { @@ -59,13 +65,25 @@ class Deploy {
59 }) 65 })
60 } 66 }
61 67
  68 + _flush() {
  69 + var self = this;
  70 +
  71 + return rp({
  72 + uri: 'http://flushcache.yoho.cn/flushdaction.php',
  73 + type: 'GET',
  74 + qs: {
  75 + url: `http://cdn.yoho.cn/${self.project.name}/${self.building.version}/`
  76 + }
  77 + }).then(data => {
  78 + console.log(data);
  79 + });
  80 + }
  81 +
62 82
63 async _state(state) { 83 async _state(state) {
64 ws.broadcast(`/deploy/${this.project._id}`, { 84 ws.broadcast(`/deploy/${this.project._id}`, {
65 - host: this.info.host,  
66 state: state 85 state: state
67 }); 86 });
68 - await DeployInfo.updateState(this.info._id, state);  
69 } 87 }
70 88
71 _log(msg) { 89 _log(msg) {
@@ -162,8 +162,7 @@ @@ -162,8 +162,7 @@
162 }); 162 });
163 163
164 ws.on('/deploy/{{project._id}}', function(data) { 164 ws.on('/deploy/{{project._id}}', function(data) {
165 - console.log(data);  
166 - $('#d-' + data.host.replace(/\./g, '-')).find('b').text(data.state); 165 + layer.msg(data.state);
167 }); 166 });
168 }); 167 });
169 ws.on('error', function() { 168 ws.on('error', function() {
@@ -55,6 +55,7 @@ @@ -55,6 +55,7 @@
55 "nedb": "^1.8.0", 55 "nedb": "^1.8.0",
56 "nedb-promise": "^2.0.0", 56 "nedb-promise": "^2.0.0",
57 "qs": "^6.2.0", 57 "qs": "^6.2.0",
  58 + "request-promise": "^4.1.1",
58 "shelljs": "^0.7.0", 59 "shelljs": "^0.7.0",
59 "socket.io": "^1.4.6", 60 "socket.io": "^1.4.6",
60 "ssh2": "^0.5.0", 61 "ssh2": "^0.5.0",