mirror of
https://github.com/Cameri/nostream.git
synced 2025-08-09 04:31:59 +02:00
feat: add WORKER_COUNT env var
Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
@@ -7,6 +7,7 @@ The following environment variables can be set:
|
||||
| Name | Description | Default |
|
||||
|------------------|--------------------------------|------------------------|
|
||||
| RELAY_PORT | Relay's server port | 8008 |
|
||||
| WORKER_COUNT | Number of workers override | No. of available CPUs |
|
||||
| DB_HOST | PostgresSQL Hostname | |
|
||||
| DB_PORT | PostgreSQL Port | 5432 |
|
||||
| DB_USER | PostgreSQL Username | nostr_ts_relay |
|
||||
|
@@ -41,6 +41,8 @@ ARG REDISHOST
|
||||
ARG REDISUSER
|
||||
ARG REDISPORT
|
||||
ARG REDISPASSWORD
|
||||
ARG DEBUG
|
||||
ARG WORKER_COUNT
|
||||
|
||||
ENV RELAY_PORT=$PORT
|
||||
ENV DB_HOST=$PGHOST
|
||||
|
@@ -18,7 +18,8 @@ export class WebServerAdapter extends EventEmitter implements IWebServerAdapter
|
||||
super()
|
||||
this.webServer
|
||||
.on('request', this.onRequest.bind(this))
|
||||
.on('clientError', this.onError.bind(this))
|
||||
.on('error', this.onError.bind(this))
|
||||
.on('clientError', this.onClientError.bind(this))
|
||||
.once('close', this.onClose.bind(this))
|
||||
.once('listening', this.onListening.bind(this))
|
||||
}
|
||||
@@ -59,7 +60,13 @@ export class WebServerAdapter extends EventEmitter implements IWebServerAdapter
|
||||
}
|
||||
}
|
||||
|
||||
private onError(error: Error, socket: Duplex) {
|
||||
private onError(error: Error) {
|
||||
debug('error: %o', error)
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
private onClientError(error: Error, socket: Duplex) {
|
||||
debug('socket error: %o', error)
|
||||
if (error['code'] === 'ECONNRESET' || !socket.writable) {
|
||||
return
|
||||
|
@@ -46,7 +46,11 @@ export class App implements IRunnable {
|
||||
logCentered(`v${packageJson.version} by Cameri`, width)
|
||||
logCentered(`NIPs implemented: ${packageJson.supportedNips}`, width)
|
||||
|
||||
const workerCount = this.settingsFactory().workers?.count || cpus().length
|
||||
const workerCount = process.env.WORKER_COUNT
|
||||
? Number(process.env.WORKER_COUNT)
|
||||
: this.settingsFactory().workers?.count || cpus().length
|
||||
|
||||
debug('env: %O', process.env)
|
||||
|
||||
for (let i = 0; i < workerCount; i++) {
|
||||
debug('starting worker')
|
||||
@@ -81,7 +85,7 @@ export class App implements IRunnable {
|
||||
}
|
||||
|
||||
private onExit() {
|
||||
debug('exiting')
|
||||
console.log('exiting')
|
||||
this.process.exit(0)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user