Skip to content

Commit

Permalink
feat: Add DB connect time out ms
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdt committed Feb 12, 2024
1 parent aea10ef commit 6742b29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LIGHTBRIDGE_RPC_ARBITRUMMAINNET=
LIGHTBRIDGE_RPC_OPTIMISMMAINNET=
# DB settings
LIGHTBRIDGE_POSTGRES_PASSWORD=abcdef
LIGHTBRIDGE_POSTGRES_CONNECT_TIMEOUT_MS=
LIGHTBRIDGE_POSTGRES_DB_HOST=LIGHTBRIDGE_db
LIGHTBRIDGE_POSTGRES_DB=postgres
LIGHTBRIDGE_POSTGRES_PORT=5432
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ This service monitors the on-chain events and release funds when a new deposit i

All configuration is done via environment variables. See all variables at [.env.example](.env.example); copy into a `.env` file before running.

| | Description | Default |
|-------------------------------------|----------------------------------------------------|----------------|
| RPC_URL | The endpoint of Layer 2 | |
| LIGHTBRIDGE_REJECT_UNAUTHORIZED | Allows self-signed certificates if false (TypeORM) | true |
| LIGHTBRIDGE_DISBURSER_KEY | The pk of disburser | |
| LIGHTBRIDGE_POLLING_INTERVAL | The polling interval of fetching events | 60s |
| LIGHTBRIDGE_BLOCK_RANGE_PER_POLLING | The blcock range of each polling | 1000 |
| LIGHTBRIDGE_POSTGRES_PASSWORD | The database password | abcdef |
| LIGHTBRIDGE_POSTGRES_DB_HOST | The database host | LIGHTBRIDGE_db |
| LIGHTBRIDGE_POSTGRES_DB | The database name | postgres |
| LIGHTBRIDGE_POSTGRES_PORT | The database port | 5432 |
| LIGHTBRIDGE_POSTGRES_USER | The database user | postgres |
| | Description | Default |
|-----------------------------------------|----------------------------------------------------|-----------------|
| RPC_URL | The endpoint of Layer 2 | |
| LIGHTBRIDGE_REJECT_UNAUTHORIZED | Allows self-signed certificates if false (TypeORM) | true |
| LIGHTBRIDGE_DISBURSER_KEY | The pk of disburser | |
| LIGHTBRIDGE_POLLING_INTERVAL | The polling interval of fetching events | 60s |
| LIGHTBRIDGE_BLOCK_RANGE_PER_POLLING | The blcock range of each polling | 1000 |
| LIGHTBRIDGE_POSTGRES_CONNECT_TIMEOUT_MS | DB connect timeout in ms | Typeorm default |
| LIGHTBRIDGE_POSTGRES_PASSWORD | The database password | abcdef |
| LIGHTBRIDGE_POSTGRES_DB_HOST | The database host | LIGHTBRIDGE_db |
| LIGHTBRIDGE_POSTGRES_DB | The database name | postgres |
| LIGHTBRIDGE_POSTGRES_PORT | The database port | 5432 |
| LIGHTBRIDGE_POSTGRES_USER | The database user | postgres |

## Building & Running

Expand Down
20 changes: 14 additions & 6 deletions src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { LastAirdrop } from './entities/LastAirdrop.entity'

dotenv.config()

console.log("SSL: Rejecting unauthorized -> ", process.env.LIGHTBRIDGE_REJECT_UNAUTHORIZED)
console.log(
'SSL: Rejecting unauthorized -> ',
process.env.LIGHTBRIDGE_REJECT_UNAUTHORIZED
)

export const AppDataSource = new DataSource({
type: 'postgres',
Expand All @@ -23,11 +26,16 @@ export const AppDataSource = new DataSource({
migrations: [],
subscribers: [],
// ssl obj needs to be undefined to still allow for non-encrypted connections
ssl: process.env.LIGHTBRIDGE_REJECT_UNAUTHORIZED?.toLowerCase() === 'true' ? undefined : {
// prod = false (self-signed certificates need to be allowed in prod for aws deployment), dev = true
rejectUnauthorized: false
},
connectTimeoutMS: 10000,
ssl:
process.env.LIGHTBRIDGE_REJECT_UNAUTHORIZED?.toLowerCase() === 'true'
? undefined
: {
// prod = false (self-signed certificates need to be allowed in prod for aws deployment), dev = true
rejectUnauthorized: false,
},
connectTimeoutMS: process.env.LIGHTBRIDGE_POSTGRES_CONNECT_TIMEOUT_MS
? parseInt(process.env.LIGHTBRIDGE_POSTGRES_CONNECT_TIMEOUT_MS)
: undefined,
})

export const historyDataRepository = AppDataSource.getRepository(HistoryData)
Expand Down

0 comments on commit 6742b29

Please sign in to comment.