Skip to content

Commit

Permalink
clear fetch tkk interval on exit (finally no need for mocha --exit)
Browse files Browse the repository at this point in the history
  • Loading branch information
guyrotem committed May 1, 2019
1 parent 731e91d commit e308703
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint": "eslint lib/ *.js test/ && echo Lint passed.",
"test": "npm run lint && npm run test-ci",
"test-browser": "node test/browser/start.js",
"test-ci": "mocha test/spec/*.js --exit",
"test-ci": "mocha test/spec/*.js",
"test-cov": "nyc mocha test/spec/*.js"
},
"license": "Apache-2.0",
Expand Down
7 changes: 6 additions & 1 deletion scripts/core/translate-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ function initServer() {
});

return q.all([fetchTkkWithExponentialBackoff(), loadLanguages()])
.then(() => {setInterval(refreshTkk, 45 * 60 * 1000);});
.then(() => {
const interval = setInterval(refreshTkk, 45 * 60 * 1000);
return {
close: () => clearInterval(interval)
}
});
}

function fetchTkkWithExponentialBackoff() {
Expand Down
7 changes: 6 additions & 1 deletion scripts/init-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ function start() {
topologyManager.init();

return postgresDb.init(process.env.DATABASE_URL)
.then(() => translateAPI.init());
.then(() => translateAPI.init())
.then((closeHandler) => {
return {
stop: () => closeHandler.close()
}
});
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions scripts/run-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function startServer() {
console.log(`Server listening on: ${port}`);
});

return initManager.start().then(() => {
return initManager.start().then((initManagerStopHandle) => {
return {
stop: () => {
const deferred = q.defer();
Expand All @@ -33,7 +33,7 @@ function startServer() {
deferred.resolve();
});

return deferred.promise;
return q.all([deferred.promise, initManagerStopHandle.stop()]);
}
}
});
Expand Down

0 comments on commit e308703

Please sign in to comment.