Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #1978, add a $CONTROLLER_SINGLETON variable that controls if this…
Browse files Browse the repository at this point in the history
… server instance should handle database upgrades and periodic tasks
  • Loading branch information
ianb committed Dec 13, 2016
1 parent 85db7e7 commit 2d4df88
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ CLIENT_SECRET=efde5874713abf2a8ec9d8af8488fae7c7e0a933dba08208f644fa93b5622dab
SHOW_STACK_TRACES=true
LOG_LINT=true
LOG_LEVEL=debug
CONTROLLER_SINGLETON=true
# To test caching locally:
#SET_CACHE=true
7 changes: 7 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ var conf = convict({
default: true,
env: "SET_CACHE",
arg: "set-cache"
},
controllerSingleton: {
doc: "If true, then this ONE server should be the one that runs migrations and periodic tasks",
format: Boolean,
default: false,
env: "CONTROLLER_SINGLETON",
arg: "controller-singleton"
}
});

Expand Down
4 changes: 4 additions & 0 deletions server/src/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const ua = require("universal-analytics");
let checkDeletedInterval = config.checkDeletedInterval * 1000;

exports.start = function () {
if (! config.controllerSingleton) {
console.info("Note: not performing periodic tasks in this server");
return;
}

//setInterval(require("./exporter").cleanExports, keepTime / 10);

Expand Down
9 changes: 6 additions & 3 deletions server/src/pages/metrics/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function safeStoreQueries() {
});
}

if (config.refreshMetricsTime) {
if (config.refreshMetricsTime && config.controllerSingleton) {
// Randomize each worker +-30 seconds interval
let interval = config.refreshMetricsTime * 1000 + Math.floor(Math.random()*60000 - 30000);
if (interval < 10000) {
Expand All @@ -39,5 +39,8 @@ if (config.refreshMetricsTime) {
} else {
console.info("Not running periodic metrics updating");
}
// Also run immediately on startup:
setTimeout(safeStoreQueries, 1000);

if (config.controllerSingleton) {
// Also run immediately on startup:
setTimeout(safeStoreQueries, 1000);
}
4 changes: 4 additions & 0 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ if (config.useS3) {


function initDatabase() {
if (! config.controllerSingleton) {
console.info("Note: this server will not perform database initialization");
return Promise.resolve();
}
dbschema.createTables().then(() => {
return dbschema.createKeygrip();
}).then(() => {
Expand Down

0 comments on commit 2d4df88

Please sign in to comment.