Skip to content

Commit c784c6f

Browse files
committed
Fix async returns
1 parent 88a449a commit c784c6f

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

lib/dump_restbase.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ function dumpWiki(options) {
2222
var dumpName = dumpDBName(domain);
2323
var workDB = options.workDir + '/' + dumpName;
2424
var dumpDB = options.dumpDir + '/' + dumpName + '.xz';
25+
2526
// If a dump exists, uncompress it & use it as a starting point
2627
var dumpPromise = P.resolve();
2728
if (fs.existsSync(dumpDB)) {
2829
dumpPromise = proc.execFileAsync('pixz', ['-d', dumpDB, workDB]);
2930
}
31+
3032
return dumpPromise
3133
.then(function() {
3234
var dumpOptions = {
@@ -41,9 +43,8 @@ function dumpWiki(options) {
4143
})
4244
.then(function() {
4345
console.log('xz compressing');
44-
proc.execFileAsync('pixz', ['-2', workDB, dumpDB]);
46+
return proc.execFileAsync('pixz', ['-2', workDB, dumpDB]);
4547
})
46-
.catch(console.log)
4748
.then(function() {
4849
return fs.unlinkAsync(workDB);
4950
})
@@ -64,7 +65,10 @@ function dumpAllWikis (options) {
6465
return P.each(res.body.items, function(domain) {
6566
console.log(domain);
6667
options.domain = domain;
67-
return dumpWiki(options);
68+
return dumpWiki(options)
69+
.catch(function(res) {
70+
console.log(domain, res);
71+
});
6872
});
6973
})
7074
.then(function() {

lib/htmldump.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ var PromiseStream = require('./PromiseStream');
2323
var maxConcurrency = 50;
2424

2525
function getArticles (options, res) {
26-
var next = res.next || '';
27-
if (next === 'finished') {
26+
if (!res || res.next === 'finished') {
2827
// nothing more to do.
29-
return P.reject('Articles done');
28+
return P.resolve(null);
3029
}
30+
var next = res.next || '';
3131

3232
var url = options.apiURL + '?action=query&generator=allpages&gapfilterredir=nonredirects'
3333
+ '&gaplimit=500&prop=revisions&gapnamespace='
@@ -51,7 +51,7 @@ function getArticles (options, res) {
5151
}
5252
});
5353
var next2 = res2['query-continue']
54-
&& res2['query-continue'].allpages.gapcontinue;
54+
&& res2['query-continue'].allpages.gapcontinue || 'finished';
5555
// XXX
5656
//next = 'finished';
5757
return {
@@ -113,9 +113,17 @@ function Dumper (articleChunkStream, options) {
113113
this.options = options;
114114
this.articles = [];
115115
this.waiters = [];
116+
this.done = false;
116117
}
117118

118119
Dumper.prototype.processArticles = function (newArticles) {
120+
if (newArticles === null) {
121+
this.done = true;
122+
while(this.waiters.length) {
123+
this.waiters.pop().resolve(null);
124+
}
125+
return;
126+
}
119127
this.articles = newArticles.articles;
120128
while(this.waiters.length && this.articles.length) {
121129
this.waiters.pop().resolve(this.articles.shift());
@@ -143,6 +151,9 @@ Dumper.prototype.next = function () {
143151
var self = this;
144152
return this.getArticle()
145153
.then(function(article) {
154+
if (article === null) {
155+
return null;
156+
}
146157
var title = article[0];
147158
var oldid = article[1];
148159
return dumpArticle(self.options, title, oldid)
@@ -164,7 +175,10 @@ function dumpLoop (options) {
164175
return new P(function(resolve, reject) {
165176
function loop () {
166177
return dumpStream.next()
167-
.then(function () {
178+
.then(function (res) {
179+
if (res === null) {
180+
return resolve();
181+
}
168182
if (i++ === 10000) {
169183
i = 0;
170184
process.nextTick(loop);
@@ -173,7 +187,11 @@ function dumpLoop (options) {
173187
}
174188
})
175189
.catch(function(e) {
176-
resolve(e);
190+
if (e instanceof String) {
191+
resolve(e);
192+
} else {
193+
reject(e);
194+
}
177195
});
178196
}
179197

lib/sqlitestore.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ SQLiteStore.prototype.saveArticle = function saveArticle (body, title, oldid) {
6969
};
7070

7171
SQLiteStore.prototype.close = function () {
72-
return this.db.closeAsync();
72+
var self = this;
73+
return P.delay(1000)
74+
.then(function() { return self.db.closeAsync(); });
7375
};
7476

7577
module.exports = function makeSQLiteStore(options) {

0 commit comments

Comments
 (0)