mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 03:46:47 +01:00
refactor(server): domain and infra modules (#6301)
This commit is contained in:
parent
26e6602ed3
commit
12dc7c48c9
9 changed files with 39 additions and 47 deletions
|
@ -37,7 +37,6 @@ export default async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
process.env.IMMICH_TEST_ENV = 'true';
|
|
||||||
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../../../server/test/e2e/immich-e2e-config.json`);
|
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../../../server/test/e2e/immich-e2e-config.json`);
|
||||||
process.env.TZ = 'Z';
|
process.env.TZ = 'Z';
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ImmichLogger } from '@app/infra/logger';
|
import { ImmichLogger } from '@app/infra/logger';
|
||||||
import { DynamicModule, Global, Module, ModuleMetadata, Provider } from '@nestjs/common';
|
import { Global, Module, Provider } from '@nestjs/common';
|
||||||
import { ActivityService } from './activity';
|
import { ActivityService } from './activity';
|
||||||
import { AlbumService } from './album';
|
import { AlbumService } from './album';
|
||||||
import { APIKeyService } from './api-key';
|
import { APIKeyService } from './api-key';
|
||||||
|
@ -31,10 +31,11 @@ const providers: Provider[] = [
|
||||||
AuditService,
|
AuditService,
|
||||||
AuthService,
|
AuthService,
|
||||||
DatabaseService,
|
DatabaseService,
|
||||||
|
ImmichLogger,
|
||||||
JobService,
|
JobService,
|
||||||
|
LibraryService,
|
||||||
MediaService,
|
MediaService,
|
||||||
MetadataService,
|
MetadataService,
|
||||||
LibraryService,
|
|
||||||
PersonService,
|
PersonService,
|
||||||
PartnerService,
|
PartnerService,
|
||||||
SearchService,
|
SearchService,
|
||||||
|
@ -46,18 +47,12 @@ const providers: Provider[] = [
|
||||||
SystemConfigService,
|
SystemConfigService,
|
||||||
TagService,
|
TagService,
|
||||||
UserService,
|
UserService,
|
||||||
ImmichLogger,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({})
|
@Module({
|
||||||
export class DomainModule {
|
imports: [],
|
||||||
static register(options: Pick<ModuleMetadata, 'imports'>): DynamicModule {
|
|
||||||
return {
|
|
||||||
module: DomainModule,
|
|
||||||
imports: options.imports,
|
|
||||||
providers: [...providers],
|
providers: [...providers],
|
||||||
exports: [...providers],
|
exports: [...providers],
|
||||||
};
|
})
|
||||||
}
|
export class DomainModule {}
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './comma
|
||||||
import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command';
|
import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DomainModule.register({ imports: [InfraModule] })],
|
imports: [InfraModule, DomainModule],
|
||||||
providers: [
|
providers: [
|
||||||
ResetAdminPasswordCommand,
|
ResetAdminPasswordCommand,
|
||||||
PromptPasswordQuestions,
|
PromptPasswordQuestions,
|
||||||
|
|
|
@ -37,7 +37,8 @@ import { ErrorInterceptor, FileUploadInterceptor } from './interceptors';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
//
|
//
|
||||||
DomainModule.register({ imports: [InfraModule] }),
|
InfraModule,
|
||||||
|
DomainModule,
|
||||||
ScheduleModule.forRoot(),
|
ScheduleModule.forRoot(),
|
||||||
TypeOrmModule.forFeature([AssetEntity]),
|
TypeOrmModule.forFeature([AssetEntity]),
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,11 +4,6 @@ import { QueueOptions } from 'bullmq';
|
||||||
import { RedisOptions } from 'ioredis';
|
import { RedisOptions } from 'ioredis';
|
||||||
|
|
||||||
function parseRedisConfig(): RedisOptions {
|
function parseRedisConfig(): RedisOptions {
|
||||||
if (process.env.IMMICH_TEST_ENV == 'true') {
|
|
||||||
// Currently running e2e tests, do not use redis
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const redisUrl = process.env.REDIS_URL;
|
const redisUrl = process.env.REDIS_URL;
|
||||||
if (redisUrl && redisUrl.startsWith('ioredis://')) {
|
if (redisUrl && redisUrl.startsWith('ioredis://')) {
|
||||||
try {
|
try {
|
||||||
|
@ -28,11 +23,9 @@ function parseRedisConfig(): RedisOptions {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const redisConfig: RedisOptions = parseRedisConfig();
|
|
||||||
|
|
||||||
export const bullConfig: QueueOptions = {
|
export const bullConfig: QueueOptions = {
|
||||||
prefix: 'immich_bull',
|
prefix: 'immich_bull',
|
||||||
connection: redisConfig,
|
connection: parseRedisConfig(),
|
||||||
defaultJobOptions: {
|
defaultJobOptions: {
|
||||||
attempts: 3,
|
attempts: 3,
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
|
|
|
@ -94,26 +94,30 @@ const providers: Provider[] = [
|
||||||
SchedulerRegistry,
|
SchedulerRegistry,
|
||||||
];
|
];
|
||||||
|
|
||||||
const imports = [
|
@Global()
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
ConfigModule.forRoot(immichAppConfig),
|
ConfigModule.forRoot(immichAppConfig),
|
||||||
TypeOrmModule.forRoot(databaseConfig),
|
TypeOrmModule.forRoot(databaseConfig),
|
||||||
TypeOrmModule.forFeature(databaseEntities),
|
TypeOrmModule.forFeature(databaseEntities),
|
||||||
ScheduleModule,
|
ScheduleModule,
|
||||||
];
|
BullModule.forRoot(bullConfig),
|
||||||
|
BullModule.registerQueue(...bullQueues),
|
||||||
const moduleExports = [...providers];
|
],
|
||||||
|
providers: [...providers],
|
||||||
if (process.env.IMMICH_TEST_ENV !== 'true') {
|
exports: [...providers, BullModule],
|
||||||
// Currently not running e2e tests, set up redis and bull queues
|
})
|
||||||
imports.push(BullModule.forRoot(bullConfig));
|
export class InfraModule {}
|
||||||
imports.push(BullModule.registerQueue(...bullQueues));
|
|
||||||
moduleExports.push(BullModule);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
imports,
|
imports: [
|
||||||
|
ConfigModule.forRoot(immichAppConfig),
|
||||||
|
TypeOrmModule.forRoot(databaseConfig),
|
||||||
|
TypeOrmModule.forFeature(databaseEntities),
|
||||||
|
ScheduleModule,
|
||||||
|
],
|
||||||
providers: [...providers],
|
providers: [...providers],
|
||||||
exports: moduleExports,
|
exports: [...providers],
|
||||||
})
|
})
|
||||||
export class InfraModule {}
|
export class InfraTestModule {}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Module, OnModuleInit } from '@nestjs/common';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DomainModule.register({ imports: [InfraModule] })],
|
imports: [InfraModule, DomainModule],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class MicroservicesModule implements OnModuleInit {
|
export class MicroservicesModule implements OnModuleInit {
|
||||||
|
|
|
@ -47,7 +47,6 @@ export default async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
process.env.IMMICH_TEST_ENV = 'true';
|
|
||||||
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/immich-e2e-config.json`);
|
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/immich-e2e-config.json`);
|
||||||
process.env.TZ = 'Z';
|
process.env.TZ = 'Z';
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { AssetCreate, IJobRepository, JobItem, JobItemHandler, LibraryResponseDto, QueueName } from '@app/domain';
|
import { AssetCreate, IJobRepository, JobItem, JobItemHandler, LibraryResponseDto, QueueName } from '@app/domain';
|
||||||
import { AppModule } from '@app/immich';
|
import { AppModule } from '@app/immich';
|
||||||
import { dataSource } from '@app/infra';
|
import { InfraModule, InfraTestModule, dataSource } from '@app/infra';
|
||||||
import { AssetEntity, AssetType, LibraryType } from '@app/infra/entities';
|
import { AssetEntity, AssetType, LibraryType } from '@app/infra/entities';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import { Test } from '@nestjs/testing';
|
import { Test } from '@nestjs/testing';
|
||||||
|
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
@ -69,6 +68,8 @@ export const testApp = {
|
||||||
const { jobs } = options || { jobs: false };
|
const { jobs } = options || { jobs: false };
|
||||||
|
|
||||||
const moduleFixture = await Test.createTestingModule({ imports: [AppModule], providers: [AppService] })
|
const moduleFixture = await Test.createTestingModule({ imports: [AppModule], providers: [AppService] })
|
||||||
|
.overrideModule(InfraModule)
|
||||||
|
.useModule(InfraTestModule)
|
||||||
.overrideProvider(IJobRepository)
|
.overrideProvider(IJobRepository)
|
||||||
.useValue({
|
.useValue({
|
||||||
addHandler: (_queueName: QueueName, _concurrency: number, handler: JobItemHandler) => (_handler = handler),
|
addHandler: (_queueName: QueueName, _concurrency: number, handler: JobItemHandler) => (_handler = handler),
|
||||||
|
|
Loading…
Reference in a new issue