mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 03:46:47 +01:00
feat(server): turn off machine learning endpoint (#1361)
This commit is contained in:
parent
a8cbda5f24
commit
bdad18a572
5 changed files with 25 additions and 12 deletions
|
@ -9,6 +9,7 @@ import { GetJobDto, JobId } from './dto/get-job.dto';
|
||||||
import { JobStatusResponseDto } from './response-dto/job-status-response.dto';
|
import { JobStatusResponseDto } from './response-dto/job-status-response.dto';
|
||||||
import { IMachineLearningJob } from '@app/job/interfaces/machine-learning.interface';
|
import { IMachineLearningJob } from '@app/job/interfaces/machine-learning.interface';
|
||||||
import { StorageService } from '@app/storage';
|
import { StorageService } from '@app/storage';
|
||||||
|
import { MACHINE_LEARNING_ENABLED } from '@app/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JobService {
|
export class JobService {
|
||||||
|
@ -161,6 +162,10 @@ export class JobService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async runMachineLearningPipeline(): Promise<number> {
|
private async runMachineLearningPipeline(): Promise<number> {
|
||||||
|
if (!MACHINE_LEARNING_ENABLED) {
|
||||||
|
throw new BadRequestException('Machine learning is not enabled.');
|
||||||
|
}
|
||||||
|
|
||||||
const jobCount = await this.machineLearningQueue.getJobCounts();
|
const jobCount = await this.machineLearningQueue.getJobCounts();
|
||||||
|
|
||||||
if (jobCount.waiting > 0) {
|
if (jobCount.waiting > 0) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { SERVER_VERSION } from './constants/server_version.constant';
|
||||||
import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
|
import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
|
||||||
import { json } from 'body-parser';
|
import { json } from 'body-parser';
|
||||||
import { patchOpenAPI } from './utils/patch-open-api.util';
|
import { patchOpenAPI } from './utils/patch-open-api.util';
|
||||||
import { getLogLevels } from '@app/common';
|
import { getLogLevels, MACHINE_LEARNING_ENABLED } from '@app/common';
|
||||||
|
|
||||||
const logger = new Logger('ImmichServer');
|
const logger = new Logger('ImmichServer');
|
||||||
|
|
||||||
|
@ -69,5 +69,7 @@ async function bootstrap() {
|
||||||
const envName = (process.env.NODE_ENV || 'development').toUpperCase();
|
const envName = (process.env.NODE_ENV || 'development').toUpperCase();
|
||||||
logger.log(`Running Immich Server in ${envName} environment - version ${SERVER_VERSION}`);
|
logger.log(`Running Immich Server in ${envName} environment - version ${SERVER_VERSION}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.warn(`Machine learning is ${MACHINE_LEARNING_ENABLED ? 'enabled' : 'disabled'}`);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
@ -8,8 +8,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Job } from 'bull';
|
import { Job } from 'bull';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { MACHINE_LEARNING_ENABLED, MACHINE_LEARNING_URL } from '@app/common';
|
||||||
const immich_machine_learning_url = process.env.IMMICH_MACHINE_LEARNING_URL || 'http://immich-machine-learning:3003';
|
|
||||||
|
|
||||||
@Processor(QueueName.MACHINE_LEARNING)
|
@Processor(QueueName.MACHINE_LEARNING)
|
||||||
export class MachineLearningProcessor {
|
export class MachineLearningProcessor {
|
||||||
|
@ -20,9 +19,13 @@ export class MachineLearningProcessor {
|
||||||
|
|
||||||
@Process({ name: JobName.IMAGE_TAGGING, concurrency: 2 })
|
@Process({ name: JobName.IMAGE_TAGGING, concurrency: 2 })
|
||||||
async tagImage(job: Job<IMachineLearningJob>) {
|
async tagImage(job: Job<IMachineLearningJob>) {
|
||||||
|
if (!MACHINE_LEARNING_ENABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { asset } = job.data;
|
const { asset } = job.data;
|
||||||
|
|
||||||
const res = await axios.post(immich_machine_learning_url + '/image-classifier/tag-image', {
|
const res = await axios.post(MACHINE_LEARNING_URL + '/image-classifier/tag-image', {
|
||||||
thumbnailPath: asset.resizePath,
|
thumbnailPath: asset.resizePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,10 +42,14 @@ export class MachineLearningProcessor {
|
||||||
|
|
||||||
@Process({ name: JobName.OBJECT_DETECTION, concurrency: 2 })
|
@Process({ name: JobName.OBJECT_DETECTION, concurrency: 2 })
|
||||||
async detectObject(job: Job<IMachineLearningJob>) {
|
async detectObject(job: Job<IMachineLearningJob>) {
|
||||||
|
if (!MACHINE_LEARNING_ENABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { asset }: { asset: AssetEntity } = job.data;
|
const { asset }: { asset: AssetEntity } = job.data;
|
||||||
|
|
||||||
const res = await axios.post(immich_machine_learning_url + '/object-detection/detect-object', {
|
const res = await axios.post(MACHINE_LEARNING_URL + '/object-detection/detect-object', {
|
||||||
thumbnailPath: asset.resizePath,
|
thumbnailPath: asset.resizePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
export * from './upload_location.constant';
|
export * from './upload_location.constant';
|
||||||
|
|
||||||
|
export const MACHINE_LEARNING_URL = process.env.IMMICH_MACHINE_LEARNING_URL || 'http://immich-machine-learning:3003';
|
||||||
|
export const MACHINE_LEARNING_ENABLED = MACHINE_LEARNING_URL !== 'false';
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
notificationController,
|
notificationController,
|
||||||
NotificationType
|
NotificationType
|
||||||
} from '$lib/components/shared-components/notification/notification';
|
} from '$lib/components/shared-components/notification/notification';
|
||||||
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { AllJobStatusResponseDto, api, JobCommand, JobId } from '@api';
|
import { AllJobStatusResponseDto, api, JobCommand, JobId } from '@api';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import JobTile from './job-tile.svelte';
|
import JobTile from './job-tile.svelte';
|
||||||
|
@ -95,13 +96,8 @@
|
||||||
type: NotificationType.Info
|
type: NotificationType.Info
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
console.log('[ERROR] runMachineLearning', e);
|
handleError(error, `Error running machine learning job, check console for more detail`);
|
||||||
|
|
||||||
notificationController.show({
|
|
||||||
message: `Error running machine learning job, check console for more detail`,
|
|
||||||
type: NotificationType.Error
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue