Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Add IS_PRIMARY_NODE support for selfhosted

Blue Mousea2f25bd26edb
diff --git a/backend/Dockerfile b/backend/Dockerfile
index dbaa9d5b6..23c132a4e 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -21,7 +21,8 @@ ENV TZ=UTC \
API_ORIGINS=\
PASSWORD=12345678 \
- API_KEY=
+ API_KEY=\
+ IS_PRIMARY_NODE=true
RUN apk add --no-cache tzdata && cp /usr/share/zoneinfo/$TZ /etc/localtime
WORKDIR /app
COPY --from=build /build/package*.json ./
diff --git a/backend/apps/selfhosted/src/app.module.ts b/backend/apps/selfhosted/src/app.module.ts
index 910a606e3..7c9b37a67 100644
--- a/backend/apps/selfhosted/src/app.module.ts
+++ b/backend/apps/selfhosted/src/app.module.ts
@@ -12,8 +12,9 @@ import { PingModule } from './ping/ping.module'
import { getI18nConfig } from './configs'
import { AuthModule } from './auth/auth.module'
import { AppController } from './app.controller'
+import { isPrimaryNode } from './common/utils'
-const imports = [
+const modules = [
ConfigModule.forRoot({
cache: true,
envFilePath: '.env',
@@ -23,7 +24,6 @@ const imports = [
I18nModule.forRootAsync(getI18nConfig()),
ScheduleModule.forRoot(),
NestjsFormDataModule.config({ isGlobal: true }),
- TaskManagerModule,
UserModule,
ProjectModule,
AnalyticsModule,
@@ -32,7 +32,7 @@ const imports = [
]
@Module({
- imports,
+ imports: [...modules, ...(isPrimaryNode() ? [TaskManagerModule] : [])],
controllers: [AppController],
})
export class AppModule {}
diff --git a/backend/apps/selfhosted/src/common/utils.ts b/backend/apps/selfhosted/src/common/utils.ts
index e89a9a947..337813625 100644
--- a/backend/apps/selfhosted/src/common/utils.ts
+++ b/backend/apps/selfhosted/src/common/utils.ts
@@ -679,6 +679,10 @@ const updateProjectViewClickhouse = async (viewId: string, view: any) => {
const millisecondsToSeconds = (milliseconds: number) => milliseconds / 1000
+export const isPrimaryNode = () => {
+ return process.env.IS_PRIMARY_NODE === 'true'
+}
+
const getSelfhostedUUID = (): string => {
try {
return uuidv5(SELFHOSTED_EMAIL, UUIDV5_NAMESPACE)
diff --git a/backend/docker-compose-prod.yml b/backend/docker-compose-prod.yml
index 879fe31cc..8993e4f9d 100644
--- a/backend/docker-compose-prod.yml
+++ b/backend/docker-compose-prod.yml
@@ -44,6 +44,7 @@ services:
- ENABLE_TELEGRAM_INTEGRATION=true
- TELEGRAM_BOT_TOKEN=
- SENTRY_ENABLED=true
+ - IS_PRIMARY_NODE=true
- SENTRY_DSN=
links:
- 'redis'