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