Skip to content

Commit

Permalink
Changed Redis env settings and Slack Url env setting (#242)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jo-bisonai and jo.lol authored Feb 8, 2023
1 parent 7f657cb commit 5fe6b71
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions core/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ HEALTH_CHECK_PORT=
SLACK_WEBHOOK_URL=
LOG_LEVEL=
LOG_DIR=
REDIS_HOST=
REDIS_PORT=
1 change: 1 addition & 0 deletions core/migrations/001-initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Binary file modified core/settings.sqlite
Binary file not shown.
12 changes: 8 additions & 4 deletions core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()}
Expand Down

0 comments on commit 5fe6b71

Please sign in to comment.