From 4cc65a81817ac1f5af41b42bba788233ea316bc8 Mon Sep 17 00:00:00 2001 From: yushi Date: Mon, 17 Jan 2022 12:17:15 +0800 Subject: [PATCH] add command to run the poller --- package.json | 1 + src/coin-price/poller.ts | 9 +++++++-- tsconfig.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 24762f47..14f418e5 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "postinstall": "tsc", "start": "pm2 start pm2.yaml", "stop": "pm2 stop pm2.yaml", + "start-poller": "pm2 start ./dist/coin-price/poller.js --cron '* * * * *'", "dev": "tsc-watch --onSuccess \"node ./dist/index.js\"", "eslint": "eslint src tests", "test": "mocha -r ts-node/register tests/**/*.test.ts --slow 0", diff --git a/src/coin-price/poller.ts b/src/coin-price/poller.ts index 9dd887f2..b464954f 100644 --- a/src/coin-price/poller.ts +++ b/src/coin-price/poller.ts @@ -149,7 +149,12 @@ export async function start() { } ); - client.end(); + await client.end(); } -start(); +try { + start(); +} catch(error) { + logger.error('poller error', error); + process.exit(1); +} diff --git a/tsconfig.json b/tsconfig.json index 22a58577..413bb11a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -67,5 +67,5 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "files": [ "./src/index.ts" ] + "files": [ "./src/index.ts", "./src/coin-price/poller.ts" ] }