From 1532bfc4db601d730621008a660878a9e0946d1e Mon Sep 17 00:00:00 2001 From: smart_ex Date: Thu, 30 Jun 2022 19:25:36 +1000 Subject: [PATCH] updates and fixes 2 --- Dockerfile | 1 - docker-compose.test.yml | 27 +++++++++++++++++---------- package.json | 3 ++- src/config.ts | 2 +- src/queue/health.processor.ts | 5 +++-- src/queue/worker.ts | 8 +++++--- src/services/config.service.ts | 2 ++ src/services/health.service.ts | 1 + 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 346728d..edf3f07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,3 @@ COPY --from=dev /usr/app/yarn.lock /app/ RUN yarn install && yarn cache clean -f -ENTRYPOINT ["yarn"] diff --git a/docker-compose.test.yml b/docker-compose.test.yml index a5fa014..3d85c9a 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,35 +1,37 @@ -version: '3' +version: '3.7' services: server: image: tornadocash/relayer:v5.0.0 restart: always - command: 'server' + command: 'node app/index.js' env_file: .env build: context: . dockerfile: Dockerfile ports: - 8000:8000 - depends_on: [redis] + depends_on: [ redis ] txWorker: image: tornadocash/relayer:v5.0.0 - restart: always - command: 'txWorker' + restart: unless-stopped + command: 'node txWorker.js' env_file: .env - depends_on: [redis] + depends_on: [ redis ] healthWorker: image: tornadocash/relayer:v5.0.0 - restart: always - command: 'healthWorker' + restart: unless-stopped + command: 'node healthWorker.js' env_file: .env - depends_on: [redis] + depends_on: [ redis ] redis: image: redis - restart: always + restart: unless-stopped + ports: + - 6379:6379 environment: - REDIS_APPENDONLY=yes - REDIS_APPENDFSYNC=always @@ -38,3 +40,8 @@ services: volumes: redis: + +#networks: +# default: +# external: true +# name: frontend_default diff --git a/package.json b/package.json index 797eeba..9976cc7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "txWorker": "node txWorker.js", "healthWorker": "node healthWorker.js", "dev:server": "nodemon --watch './src/**/*.ts' --exec ts-node src/app/index.ts", - "dev:worker": "nodemon --watch './src/**/*.ts' --exec ts-node src/worker.ts", + "dev:healthWorker": "nodemon --watch './src/**/*.ts' --exec ts-node src/healthWorker.ts", + "dev:txWorker": "nodemon --watch './src/**/*.ts' --exec ts-node src/txWorker.ts", "build": "tsc", "eslint": "eslint --ext .ts --ignore-path .gitignore .", "prettier:check": "npx prettier --check . --config .prettierrc", diff --git a/src/config.ts b/src/config.ts index 0e950b9..b7c26d3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,7 +6,7 @@ const isProduction = process.env.NODE_ENV === 'production'; export const relayerVersion = require(`${isProduction ? '.' : '..'}/package.json`).version; export const netId = Number(process.env.NET_ID || 1); export const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379'; -export const rpcUrl = process.env.RPC_URL; +export const rpcUrl = process.env.HTTP_RPC_URL; export const mainnetRpcUrl = process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/'; export const offchainOracleAddress = '0x07D91f5fb9Bf7798734C3f606dB065549F6893bb'; export const multiCallAddress = '0xda3c19c6fe954576707fa24695efb830d9cca1ca'; diff --git a/src/queue/health.processor.ts b/src/queue/health.processor.ts index bd156b6..94053b4 100644 --- a/src/queue/health.processor.ts +++ b/src/queue/health.processor.ts @@ -3,13 +3,14 @@ import { Processor } from 'bullmq'; export const healthProcessor: Processor = async () => { const healthService = getHealthService(); - try { - await healthService.check(); + const status = await healthService.check(); await healthService.clearErrorCodes(); await healthService.setStatus({ status: true, error: '' }); + return status; } catch (e) { await healthService.saveError(e); await healthService.setStatus({ status: false, error: e.message }); + return { error: e.message }; } }; diff --git a/src/queue/worker.ts b/src/queue/worker.ts index 4e351bc..165a9c8 100644 --- a/src/queue/worker.ts +++ b/src/queue/worker.ts @@ -11,7 +11,7 @@ export const priceWorker = async () => { console.log('price worker', price.queue.name); price.worker.on('active', () => console.log('worker active')); price.worker.on('completed', async (job, result) => { - console.log(`Job ${job.id} completed with result: ${result}`); + console.log(`Job ${job.name} completed with result: `, result); }); price.worker.on('failed', (job, error) => healthService.saveError(error)); }; @@ -31,12 +31,14 @@ export const relayerWorker = async () => { }; export const healthWorker = async () => { + console.log('health worker starting'); await configService.init(); const health = new HealthQueueHelper(); - health.scheduler.on('stalled', (jobId, prev) => console.log({ jobId, prev })); console.log(health.queue.name, 'worker started'); + + health.scheduler.on('stalled', (jobId, prev) => console.log({ jobId, prev })); health.worker.on('completed', (job, result) => { - console.log(`Job ${job.id} completed with result: `, result); + console.log(`Job ${job.name} completed with result: `, result); }); health.worker.on('failed', (job, error) => { console.log(error); diff --git a/src/services/config.service.ts b/src/services/config.service.ts index 16ec101..5893667 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -100,6 +100,7 @@ export class ConfigService { } async checkNetwork() { + console.log('Checking network...'); await this.provider.getNetwork(); if (this.isLightMode) { await this.mainnentProvider.getNetwork(); @@ -110,6 +111,7 @@ export class ConfigService { try { if (this.isInit) return; await this.checkNetwork(); + console.log('Initializing...'); this._tokenAddress = await resolve(torn.torn.address); this._tokenContract = await getTornTokenContract(this._tokenAddress); if (this.isLightMode) { diff --git a/src/services/health.service.ts b/src/services/health.service.ts index 6141d48..9eb6af8 100644 --- a/src/services/health.service.ts +++ b/src/services/health.service.ts @@ -127,6 +127,7 @@ export class HealthService { if (tornStatus.level === 'CRITICAL') { throw new RelayerError(tornStatus.message, 'INSUFFICIENT_TORN_BALANCE'); } + return { mainStatus, tornStatus }; } }