Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 91ee61c

Browse files
committed
format sync log
1 parent 1d94ba4 commit 91ee61c

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

proxy/sync_module_worker.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ SyncModuleWorker.prototype.add = function (name) {
127127
};
128128

129129
SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
130+
this.log('----------------- Synced %s %s -------------------',
131+
name, success ? 'success' : 'fail');
130132
if (success) {
131133
this.pushSuccess(name);
132134
} else {
@@ -136,7 +138,6 @@ SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
136138
var that = this;
137139
// relase the stack: https://github.com/cnpm/cnpmjs.org/issues/328
138140
defer.setImmediate(function *() {
139-
that.log('[c#%s] setImmediate after, %s done, start next...', concurrencyId, name);
140141
yield *that.next(concurrencyId);
141142
});
142143
};
@@ -159,7 +160,7 @@ SyncModuleWorker.prototype.syncUpstream = function* (name) {
159160

160161
var logURL = url + '/log/' + r.data.logId;
161162
var offset = 0;
162-
this.log('Syncing upstream %s', logURL);
163+
this.log('----------------- Syncing upstream %s -------------------', logURL);
163164

164165
var count = 0;
165166
while (true) {
@@ -178,25 +179,31 @@ SyncModuleWorker.prototype.syncUpstream = function* (name) {
178179

179180
var data = rs.data;
180181
var syncDone = false;
181-
if (data.log.indexOf('[done] Sync') >= 0) {
182+
if (data.log && data.log.indexOf('[done] Sync') >= 0) {
182183
syncDone = true;
183-
data.log = data.log.replace('[done] Sync', '[upstream sync done]') +
184-
'\n-------------------------------------------------------------\n';
184+
data.log = data.log.replace('[done] Sync', '[Upstream done] Sync');
185+
}
186+
187+
if (data.log) {
188+
this.log(data.log);
185189
}
186-
this.log(data.log);
187190

188191
if (syncDone) {
189192
break;
190193
}
194+
191195
if (count >= 30) {
192-
this.log('sync upstream %s fail, give up %s',
193-
logURL, '\n-------------------------------------------------------------\n');
196+
this.log('sync upstream %s fail, give up', logURL);
194197
break;
195198
}
196199

197-
offset += data.log.split('\n').length;
200+
if (data.log) {
201+
offset += data.log.split('\n').length;
202+
}
203+
198204
yield sleep(2000);
199205
}
206+
this.log('----------------- Synced upstream %s -------------------', logURL);
200207
};
201208

202209
SyncModuleWorker.prototype.next = function *(concurrencyId) {
@@ -215,6 +222,8 @@ SyncModuleWorker.prototype.next = function *(concurrencyId) {
215222
yield* this.syncUpstream(name);
216223
}
217224

225+
this.log('----------------- Syncing %s -------------------', name);
226+
218227
// get from npm
219228
try {
220229
var result = yield npm.request('/' + name);
@@ -270,9 +279,9 @@ SyncModuleWorker.prototype.next = function *(concurrencyId) {
270279
return;
271280
}
272281

273-
that.log('[c#%d] [%s] synced success, %d versions: %s',
282+
this.log('[c#%d] [%s] synced success, %d versions: %s',
274283
concurrencyId, name, versions.length, versions.join(', '));
275-
yield* that._doneOne(concurrencyId, name, true);
284+
yield* this._doneOne(concurrencyId, name, true);
276285
};
277286

278287
function *_listStarUsers(modName) {

0 commit comments

Comments
 (0)