mirror of
https://github.com/immich-app/immich.git
synced 2025-12-14 17:23:36 +03:00
Compare commits
1 Commits
revert-sve
...
feat/maint
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab764f2423 |
@@ -8,6 +8,8 @@ import { OpenTelemetryModule } from 'nestjs-otel';
|
|||||||
import { commands } from 'src/commands';
|
import { commands } from 'src/commands';
|
||||||
import { IWorker } from 'src/constants';
|
import { IWorker } from 'src/constants';
|
||||||
import { controllers } from 'src/controllers';
|
import { controllers } from 'src/controllers';
|
||||||
|
import { MaintenanceController } from 'src/controllers/maintenance.controller';
|
||||||
|
import { ServerController } from 'src/controllers/server.controller';
|
||||||
import { ImmichWorker } from 'src/enum';
|
import { ImmichWorker } from 'src/enum';
|
||||||
import { AuthGuard } from 'src/middleware/auth.guard';
|
import { AuthGuard } from 'src/middleware/auth.guard';
|
||||||
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
|
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
|
||||||
@@ -95,6 +97,13 @@ export class ApiModule extends BaseModule {}
|
|||||||
})
|
})
|
||||||
export class MicroservicesModule extends BaseModule {}
|
export class MicroservicesModule extends BaseModule {}
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [...imports],
|
||||||
|
controllers: [MaintenanceController, ServerController],
|
||||||
|
providers: [...common, { provide: IWorker, useValue: ImmichWorker.MAINTENANCE }, SchedulerRegistry],
|
||||||
|
})
|
||||||
|
export class MaintenanceModule extends BaseModule {}
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [...imports],
|
imports: [...imports],
|
||||||
providers: [...common, ...commands, SchedulerRegistry],
|
providers: [...common, ...commands, SchedulerRegistry],
|
||||||
|
|||||||
17
server/src/controllers/maintenance.controller.ts
Normal file
17
server/src/controllers/maintenance.controller.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { ServerPingResponse } from 'src/dtos/server.dto';
|
||||||
|
import { Authenticated } from 'src/middleware/auth.guard';
|
||||||
|
import { MaintenanceService } from 'src/services/maintenance.service';
|
||||||
|
|
||||||
|
@ApiTags('Maintenance')
|
||||||
|
@Controller('maintenance')
|
||||||
|
export class MaintenanceController {
|
||||||
|
constructor(private service: MaintenanceService) {}
|
||||||
|
|
||||||
|
@Get('ping')
|
||||||
|
@Authenticated()
|
||||||
|
getPing(): ServerPingResponse {
|
||||||
|
return this.service.ping();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -389,6 +389,7 @@ export enum ImmichEnvironment {
|
|||||||
export enum ImmichWorker {
|
export enum ImmichWorker {
|
||||||
API = 'api',
|
API = 'api',
|
||||||
MICROSERVICES = 'microservices',
|
MICROSERVICES = 'microservices',
|
||||||
|
MAINTENANCE = 'maintenance',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ImmichTelemetry {
|
export enum ImmichTelemetry {
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ const getEnv = (): EnvData => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const includedWorkers = asSet(dto.IMMICH_WORKERS_INCLUDE, [ImmichWorker.API, ImmichWorker.MICROSERVICES]);
|
const includedWorkers = asSet(dto.IMMICH_WORKERS_INCLUDE, [
|
||||||
|
// ImmichWorker.API,
|
||||||
|
// ImmichWorker.MICROSERVICES,
|
||||||
|
ImmichWorker.MAINTENANCE,
|
||||||
|
]);
|
||||||
const excludedWorkers = asSet(dto.IMMICH_WORKERS_EXCLUDE, []);
|
const excludedWorkers = asSet(dto.IMMICH_WORKERS_EXCLUDE, []);
|
||||||
const workers = [...setDifference(includedWorkers, excludedWorkers)];
|
const workers = [...setDifference(includedWorkers, excludedWorkers)];
|
||||||
for (const worker of workers) {
|
for (const worker of workers) {
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ export interface ClientEventMap {
|
|||||||
on_new_release: [ReleaseNotification];
|
on_new_release: [ReleaseNotification];
|
||||||
on_notification: [NotificationDto];
|
on_notification: [NotificationDto];
|
||||||
on_session_delete: [string];
|
on_session_delete: [string];
|
||||||
|
shutdown_worker: [ImmichWorker];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventItem<T extends EmitEvent> = {
|
export type EventItem<T extends EmitEvent> = {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { DownloadService } from 'src/services/download.service';
|
|||||||
import { DuplicateService } from 'src/services/duplicate.service';
|
import { DuplicateService } from 'src/services/duplicate.service';
|
||||||
import { JobService } from 'src/services/job.service';
|
import { JobService } from 'src/services/job.service';
|
||||||
import { LibraryService } from 'src/services/library.service';
|
import { LibraryService } from 'src/services/library.service';
|
||||||
|
import { MaintenanceService } from 'src/services/maintenance.service';
|
||||||
import { MapService } from 'src/services/map.service';
|
import { MapService } from 'src/services/map.service';
|
||||||
import { MediaService } from 'src/services/media.service';
|
import { MediaService } from 'src/services/media.service';
|
||||||
import { MemoryService } from 'src/services/memory.service';
|
import { MemoryService } from 'src/services/memory.service';
|
||||||
@@ -56,6 +57,7 @@ export const services = [
|
|||||||
DuplicateService,
|
DuplicateService,
|
||||||
JobService,
|
JobService,
|
||||||
LibraryService,
|
LibraryService,
|
||||||
|
MaintenanceService,
|
||||||
MapService,
|
MapService,
|
||||||
MediaService,
|
MediaService,
|
||||||
MemoryService,
|
MemoryService,
|
||||||
|
|||||||
11
server/src/services/maintenance.service.ts
Normal file
11
server/src/services/maintenance.service.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ServerPingResponse } from 'src/dtos/server.dto';
|
||||||
|
import { BaseService } from 'src/services/base.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class MaintenanceService extends BaseService {
|
||||||
|
ping(): ServerPingResponse {
|
||||||
|
// this.eventRepository.clientBroadcast();
|
||||||
|
return { res: 'Pong!' };
|
||||||
|
}
|
||||||
|
}
|
||||||
51
server/src/workers/maintenance.ts
Normal file
51
server/src/workers/maintenance.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||||
|
import { json } from 'body-parser';
|
||||||
|
import cookieParser from 'cookie-parser';
|
||||||
|
import { isMainThread } from 'node:worker_threads';
|
||||||
|
import { ApiModule, MaintenanceModule } from 'src/app.module';
|
||||||
|
import { excludePaths, serverVersion } from 'src/constants';
|
||||||
|
import { ImmichEnvironment } from 'src/enum';
|
||||||
|
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
||||||
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||||
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||||
|
import { ApiService } from 'src/services/api.service';
|
||||||
|
import { isStartUpError } from 'src/utils/misc';
|
||||||
|
|
||||||
|
export async function bootstrap() {
|
||||||
|
const app = await NestFactory.create<NestExpressApplication>(MaintenanceModule, { bufferLogs: true });
|
||||||
|
const logger = await app.resolve(LoggingRepository);
|
||||||
|
const configRepository = app.get(ConfigRepository);
|
||||||
|
|
||||||
|
const { environment, host, network } = configRepository.getEnv();
|
||||||
|
const isDev = environment === ImmichEnvironment.DEVELOPMENT;
|
||||||
|
|
||||||
|
logger.setContext('Bootstrap');
|
||||||
|
app.useLogger(logger);
|
||||||
|
app.set('trust proxy', ['loopback', ...network.trustedProxies]);
|
||||||
|
app.set('etag', 'strong');
|
||||||
|
app.use(cookieParser());
|
||||||
|
app.use(json({ limit: '10mb' }));
|
||||||
|
app.useWebSocketAdapter(new WebSocketAdapter(app));
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
app.enableCors();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.setGlobalPrefix('api', { exclude: excludePaths });
|
||||||
|
|
||||||
|
app.use(app.get(ApiService).ssr(excludePaths));
|
||||||
|
|
||||||
|
await (host ? app.listen(2283, host) : app.listen(2283));
|
||||||
|
|
||||||
|
logger.log(`Immich Maintenance is listening on ${await app.getUrl()} [v${serverVersion}] [${environment}] `);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMainThread) {
|
||||||
|
bootstrap().catch((error) => {
|
||||||
|
if (!isStartUpError(error)) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user