Ver código fonte

run cron only on the first instance/cluster of the app

Pouria Ezzati 1 ano atrás
pai
commit
c8a49d83fd
1 arquivos alterados com 9 adições e 1 exclusões
  1. 9 1
      server/server.js

+ 9 - 1
server/server.js

@@ -16,7 +16,15 @@ const links = require("./handlers/links.handler");
 const routes = require("./routes");
 const utils = require("./utils");
 
-require("./cron");
+
+// run the cron jobs
+// the app might be running in cluster mode (multiple instances) so run the cron job only on one cluster (the first one)
+// NODE_APP_INSTANCE variable is added by pm2 automatically, if you're using something else to cluster your app, then make sure to set this variable
+if (env.NODE_APP_INSTANCE === 0) {
+  require("./cron");
+}
+
+// intialize passport authentication library
 require("./passport");
 
 // create express app