Skip to content

Commit

Permalink
Allow disabling part of the application so the app could be split int…
Browse files Browse the repository at this point in the history
…o several processes
  • Loading branch information
ArsenyYankovsky committed Oct 7, 2020
1 parent 134cd3c commit 58eea30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/config.ts
Expand Up @@ -17,6 +17,14 @@ class Config {
return (process.env.BACKGROUND_JOBS_ENABLED && Boolean(process.env.BACKGROUND_JOBS_ENABLED)) || true
}

get tracingApiEnabled() {
return (process.env.TRACING_API_ENABLED && Boolean(process.env.TRACING_API_ENABLED)) || true
}

get uiEnabled() {
return (process.env.UI_ENABLED && Boolean(process.env.UI_ENABLED)) || true
}

get enrichmentJobBatchSize() {
return (process.env.ENRICHMENT_JOB_BATCH_SIZE && Number(process.env.ENRICHMENT_JOB_BATCH_SIZE)) || 1000
}
Expand Down
2 changes: 0 additions & 2 deletions src/cron/analyze-errors.job.ts
Expand Up @@ -16,8 +16,6 @@ export const analyzeNewTraces = new CronJob('0 * * * * *', async () => {
isRunning = true

try {
logger.debug('Enriching new traces')

let tracesToAnalyze
let offset = 0
do {
Expand Down
21 changes: 13 additions & 8 deletions src/index.ts
Expand Up @@ -8,8 +8,6 @@ import { startCronJobs } from './cron'
import { createDbConnection } from './db/pg'
import { config } from './config'

const trackingPort = config.trackingPort

const httpServer = http.createServer(trackingApi)

const uiPort = config.uiPort
Expand All @@ -36,15 +34,22 @@ const start = async () => {
console.log('Error while trying to connect to db: ', err)
process.exit(1)
}

console.log('Successfully connected to db')

httpServer.listen(trackingPort, () => {
console.log(`Tracking handler listening on port ${trackingPort}`)
})
if (config.tracingApiEnabled) {
const trackingPort = config.trackingPort

graphqlServer.listen(uiPort, () => {
console.log(`UI app listening on port ${uiPort}`)
})
httpServer.listen(trackingPort, () => {
console.log(`Tracking handler listening on port ${trackingPort}`)
})
}

if (config.uiEnabled) {
graphqlServer.listen(uiPort, () => {
console.log(`UI app listening on port ${uiPort}`)
})
}

if (config.backgroundJobsEnabled) {
startCronJobs()
Expand Down

0 comments on commit 58eea30

Please sign in to comment.