From 5fe6b7171d65596db4f5a443ef283ea4df817599 Mon Sep 17 00:00:00 2001 From: "jo.lol" Date: Wed, 8 Feb 2023 13:17:53 +0900 Subject: [PATCH] Changed Redis env settings and Slack Url env setting (#242) * Changed redis env settings and slack env * add env to .env.example * fixed delete migration file for TEST * fixed add changed settings.sqlite --------- Co-authored-by: jo.lol --- core/.env.example | 2 ++ core/migrations/001-initial.sql | 1 + core/settings.sqlite | Bin 65536 -> 65536 bytes core/src/settings.ts | 12 ++++++++---- core/src/utils.ts | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/.env.example b/core/.env.example index 557b46a8e..79f0761f1 100644 --- a/core/.env.example +++ b/core/.env.example @@ -5,3 +5,5 @@ HEALTH_CHECK_PORT= SLACK_WEBHOOK_URL= LOG_LEVEL= LOG_DIR= +REDIS_HOST= +REDIS_PORT= \ No newline at end of file diff --git a/core/migrations/001-initial.sql b/core/migrations/001-initial.sql index f1014957b..e42c387bd 100644 --- a/core/migrations/001-initial.sql +++ b/core/migrations/001-initial.sql @@ -86,6 +86,7 @@ VALUES ((SELECT id from Chain WHERE name = 'localhost'), 'PUBLIC_KEY', '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'), ((SELECT id from Chain WHERE name = 'localhost'), 'LOCAL_AGGREGATOR', 'MEDIAN'), ((SELECT id from Chain WHERE name = 'localhost'), 'HEALTH_CHECK_PORT', '8888'), + ((SELECT id from Chain WHERE name = 'localhost'), 'SLACK_WEBHOOK_URL', ''), ((SELECT id from Chain WHERE name = 'localhost'), 'LISTENER_DELAY', '500'); CREATE TABLE Adapter ( diff --git a/core/settings.sqlite b/core/settings.sqlite index d05d8fa6b8b93fa6b67623fdc4520974c1c65b9c..ec46b8e556e30effbd03e02eba822d84f135f6dd 100644 GIT binary patch delta 459 zcmZo@U}u-*Jeo-2UE zo`HWCe?7nbW_{M0I9^id6G7Lvth3RC9A9zq!=xlb z6XR4%gQO(mGy_vZBbUUI#K~p#ei{abW~LVA7Kx^oCdr9Lrl!Wm7Ktfoi6$u~7A7W^ zX=av2CPt}A7HN|wJQkVMz#_)Uw}FBG2LC?(mHZ+6l6-&o9`K#u+W>UOG(H0{PF4m^ zO<^C;;1E|o*PwV8S0BenQv(Ar4xqR`Z?KP}vv+*BtCNSnzju6Skk94^eJYG%ocv)7 z{Ehr!{4;>2zUN=Zf1m$6e-_Y08~(|;^M%DZ#aKA?88J0C%x`g+94}+OdFq4nOho%* pbI)T>MgwAlNnJ-l9TZfX8J}KdR={urNLpP}M*#{pFL;q44gm96fy)2@ delta 376 zcmZo@U}W=UpZ&g6&x0yfu3tFdhU zBhMAU;mp9li@%=V8K~Tp-`I+oje(OfQJ&eL!o<|v+#=b?($Ux?$Jn*v#0%*fPb!d2(63pN4aqxoe8CV{)>iX`+dld8%cqxq*qZxq-2(g^Pu` zo0+jmnv;QBvgPDA^%5c+d?y(AZ}9KqU&$ZBFUj|Z?*ZQlp!FO0B*Zva88|hCeLRCh zT>V^w;$2*Q93xE)3^qULQ(+Y0;Ll~?Z{*MAp8?eSo_`(xeg5-6eWCo5!{!TbZkXTV xFnN)D)Z}|S8k2Qp_%~ZWIL}11!!{c|_GHu{*3arX3hJ9zKe@`h`PvIDaR5GEZK?nO diff --git a/core/src/settings.ts b/core/src/settings.ts index d7de66112..fbdd1c656 100644 --- a/core/src/settings.ts +++ b/core/src/settings.ts @@ -21,10 +21,14 @@ export const SETTINGS_DB_FILE = path.join(ORAKL_DIR, 'settings.sqlite') export const DB = await openDb() export const PROVIDER_URL = await loadKeyValuePair({ db: DB, key: 'PROVIDER_URL', chain: CHAIN }) -export const REDIS_HOST = await loadKeyValuePair({ db: DB, key: 'REDIS_HOST', chain: CHAIN }) -export const REDIS_PORT = Number( - await loadKeyValuePair({ db: DB, key: 'REDIS_PORT', chain: CHAIN }) -) +export const REDIS_HOST = + process.env.REDIS_HOST || (await loadKeyValuePair({ db: DB, key: 'REDIS_HOST', chain: CHAIN })) +export const REDIS_PORT = process.env.REDIS_PORT + ? Number(process.env.REDIS_PORT) + : Number(await loadKeyValuePair({ db: DB, key: 'REDIS_PORT', chain: CHAIN })) +export const SLACK_WEBHOOK_URL = + process.env.SLACK_WEBHOOK_URL || + (await loadKeyValuePair({ db: DB, key: 'SLACK_WEBHOOK_URL', chain: CHAIN })) export const PRIVATE_KEY = await loadKeyValuePair({ db: DB, key: 'PRIVATE_KEY', chain: CHAIN }) export const PUBLIC_KEY = await loadKeyValuePair({ db: DB, key: 'PUBLIC_KEY', chain: CHAIN }) export const LOCAL_AGGREGATOR = await loadKeyValuePair({ diff --git a/core/src/utils.ts b/core/src/utils.ts index 2c9640be0..e90fd1b81 100644 --- a/core/src/utils.ts +++ b/core/src/utils.ts @@ -5,6 +5,7 @@ import path from 'node:path' import { IcnError, IcnErrorCode } from './errors' import { IncomingWebhook } from '@slack/webhook' import Hook from 'console-hook' +import { SLACK_WEBHOOK_URL } from './settings' export async function loadJson(filepath) { const json = await Fs.readFile(filepath, 'utf8') @@ -83,9 +84,8 @@ export function mkTmpFile({ fileName }: { fileName: string }): string { } function sendToSlack(error) { - const url = process.env.SLACK_WEBHOOK_URL - if (url) { - const webhook = new IncomingWebhook(url) + if (SLACK_WEBHOOK_URL) { + const webhook = new IncomingWebhook(SLACK_WEBHOOK_URL) const text = ` :fire: _An error has occurred at_ \`${os.hostname()}\`\n \`\`\`${JSON.stringify( error )} \`\`\`\n>*System information*\n>*memory*: ${os.freemem()}/${os.totalmem()}\n>*machine*: ${os.machine()}\n>*platform*: ${os.platform()}\n>*upTime*: ${os.uptime()}\n>*version*: ${os.version()}