From dcd352ade1cc96583a1d86366fcc0a21aee77961 Mon Sep 17 00:00:00 2001 From: Yannis Barlas <yannisbarlas@gmail.com> Date: Sat, 28 Mar 2020 23:56:57 +0200 Subject: [PATCH] feat(server): add cron support --- package.json | 1 + src/app.js | 5 +++++ src/index.js | 3 +++ yarn.lock | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 06f6624..9cf3b46 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "http-status-codes": "^1.4.0", "lodash": "^4.17.15", "morgan": "^1.10.0", + "node-cron": "^2.0.3", "passport": "^0.4.1", "pubsweet-server": "^13.9.4", "waait": "^1.0.5" diff --git a/src/app.js b/src/app.js index f7e12aa..27889dc 100644 --- a/src/app.js +++ b/src/app.js @@ -103,6 +103,11 @@ const configureApp = app => { .json({ message: err.message }) }) + if (config.has('pubsweet-server.cron.path')) { + /* eslint-disable-next-line import/no-dynamic-require */ + require(config.get('pubsweet-server.cron.path')) + } + // Actions to perform when the HTTP server starts listening app.onListen = async server => { const { diff --git a/src/index.js b/src/index.js index 142c1fc..45c8e8d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +const cron = require('node-cron') + const authentication = require('pubsweet-server/src/authentication') const app = require('./app') @@ -6,5 +8,6 @@ const createJWT = authentication.token.create module.exports = { app, + cron, createJWT, } diff --git a/yarn.lock b/yarn.lock index e90d5f8..16c7a6b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4131,6 +4131,14 @@ nocache@2.1.0: resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.1.0.tgz#120c9ffec43b5729b1d5de88cd71aa75a0ba491f" integrity sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q== +node-cron@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/node-cron/-/node-cron-2.0.3.tgz#b9649784d0d6c00758410eef22fa54a10e3f602d" + integrity sha512-eJI+QitXlwcgiZwNNSRbqsjeZMp5shyajMR81RZCqeW0ZDEj4zU9tpd4nTh/1JsBiKbF8d08FCewiipDmVIYjg== + dependencies: + opencollective-postinstall "^2.0.0" + tz-offset "0.0.1" + node-fetch@^2.1.2, node-fetch@^2.2.0: version "2.6.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" @@ -4307,7 +4315,7 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -opencollective-postinstall@^2.0.2: +opencollective-postinstall@^2.0.0, opencollective-postinstall@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89" integrity sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw== @@ -5757,6 +5765,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +tz-offset@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/tz-offset/-/tz-offset-0.0.1.tgz#fef920257024d3583ed9072a767721a18bdb8a76" + integrity sha512-kMBmblijHJXyOpKzgDhKx9INYU4u4E1RPMB0HqmKSgWG8vEcf3exEfLh4FFfzd3xdQOw9EuIy/cP0akY6rHopQ== + uglify-js@^3.1.4: version "3.8.0" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.8.0.tgz#f3541ae97b2f048d7e7e3aa4f39fd8a1f5d7a805" -- GitLab