2023-12-14 17:55:40 +01:00
|
|
|
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
2024-03-25 04:02:04 +01:00
|
|
|
import { snakeCase } from 'lodash';
|
2024-05-14 21:31:36 +02:00
|
|
|
import { SystemConfigCore } from 'src/cores/system-config.core';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { mapAsset } from 'src/dtos/asset-response.dto';
|
|
|
|
import { AllJobStatusResponseDto, JobCommandDto, JobStatusDto } from 'src/dtos/job.dto';
|
2024-03-20 22:02:51 +01:00
|
|
|
import { AssetType } from 'src/entities/asset.entity';
|
2024-03-21 12:59:49 +01:00
|
|
|
import { IAssetRepository } from 'src/interfaces/asset.interface';
|
2024-03-22 23:24:02 +01:00
|
|
|
import { ClientEvent, IEventRepository } from 'src/interfaces/event.interface';
|
2024-03-21 04:15:09 +01:00
|
|
|
import {
|
|
|
|
ConcurrentQueueName,
|
|
|
|
IJobRepository,
|
|
|
|
JobCommand,
|
|
|
|
JobHandler,
|
|
|
|
JobItem,
|
|
|
|
JobName,
|
|
|
|
JobStatus,
|
|
|
|
QueueCleanType,
|
|
|
|
QueueName,
|
2024-03-21 12:59:49 +01:00
|
|
|
} from 'src/interfaces/job.interface';
|
2024-04-16 23:30:31 +02:00
|
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
2024-03-25 04:02:04 +01:00
|
|
|
import { IMetricRepository } from 'src/interfaces/metric.interface';
|
2024-03-21 12:59:49 +01:00
|
|
|
import { IPersonRepository } from 'src/interfaces/person.interface';
|
2024-05-16 00:58:23 +02:00
|
|
|
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
2023-03-20 16:55:28 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class JobService {
|
2023-06-01 12:32:51 +02:00
|
|
|
private configCore: SystemConfigCore;
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(IAssetRepository) private assetRepository: IAssetRepository,
|
2024-03-22 23:24:02 +01:00
|
|
|
@Inject(IEventRepository) private eventRepository: IEventRepository,
|
2023-05-26 21:43:24 +02:00
|
|
|
@Inject(IJobRepository) private jobRepository: IJobRepository,
|
2024-05-16 00:58:23 +02:00
|
|
|
@Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository,
|
2023-10-06 22:48:11 +02:00
|
|
|
@Inject(IPersonRepository) private personRepository: IPersonRepository,
|
2024-03-25 04:02:04 +01:00
|
|
|
@Inject(IMetricRepository) private metricRepository: IMetricRepository,
|
2024-04-16 23:30:31 +02:00
|
|
|
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
2023-06-01 12:32:51 +02:00
|
|
|
) {
|
2024-04-16 23:30:31 +02:00
|
|
|
this.logger.setContext(JobService.name);
|
2024-05-16 00:58:23 +02:00
|
|
|
this.configCore = SystemConfigCore.create(systemMetadataRepository, logger);
|
2023-06-01 12:32:51 +02:00
|
|
|
}
|
2023-05-17 19:07:17 +02:00
|
|
|
|
2023-06-16 21:36:07 +02:00
|
|
|
async handleCommand(queueName: QueueName, dto: JobCommandDto): Promise<JobStatusDto> {
|
2023-03-20 16:55:28 +01:00
|
|
|
this.logger.debug(`Handling command: queue=${queueName},force=${dto.force}`);
|
|
|
|
|
|
|
|
switch (dto.command) {
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobCommand.START: {
|
2023-06-16 21:36:07 +02:00
|
|
|
await this.start(queueName, dto);
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobCommand.PAUSE: {
|
2023-06-16 21:36:07 +02:00
|
|
|
await this.jobRepository.pause(queueName);
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobCommand.RESUME: {
|
2023-06-16 21:36:07 +02:00
|
|
|
await this.jobRepository.resume(queueName);
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-28 20:25:22 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobCommand.EMPTY: {
|
2023-06-16 21:36:07 +02:00
|
|
|
await this.jobRepository.empty(queueName);
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-12-05 03:07:20 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobCommand.CLEAR_FAILED: {
|
2023-12-05 03:07:20 +01:00
|
|
|
const failedJobs = await this.jobRepository.clear(queueName, QueueCleanType.FAILED);
|
|
|
|
this.logger.debug(`Cleared failed jobs: ${failedJobs}`);
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
}
|
2023-06-16 21:36:07 +02:00
|
|
|
|
|
|
|
return this.getJobStatus(queueName);
|
2023-03-20 16:55:28 +01:00
|
|
|
}
|
|
|
|
|
2023-04-01 22:46:07 +02:00
|
|
|
async getJobStatus(queueName: QueueName): Promise<JobStatusDto> {
|
|
|
|
const [jobCounts, queueStatus] = await Promise.all([
|
|
|
|
this.jobRepository.getJobCounts(queueName),
|
|
|
|
this.jobRepository.getQueueStatus(queueName),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return { jobCounts, queueStatus };
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:55:28 +01:00
|
|
|
async getAllJobsStatus(): Promise<AllJobStatusResponseDto> {
|
|
|
|
const response = new AllJobStatusResponseDto();
|
|
|
|
for (const queueName of Object.values(QueueName)) {
|
2023-04-01 22:46:07 +02:00
|
|
|
response[queueName] = await this.getJobStatus(queueName);
|
2023-03-20 16:55:28 +01:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async start(name: QueueName, { force }: JobCommandDto): Promise<void> {
|
2023-04-01 22:46:07 +02:00
|
|
|
const { isActive } = await this.jobRepository.getQueueStatus(name);
|
2023-03-20 16:55:28 +01:00
|
|
|
if (isActive) {
|
|
|
|
throw new BadRequestException(`Job is already running`);
|
|
|
|
}
|
|
|
|
|
2024-03-26 00:15:11 +01:00
|
|
|
this.metricRepository.jobs.addToCounter(`immich.queues.${snakeCase(name)}.started`, 1);
|
2024-03-25 04:02:04 +01:00
|
|
|
|
2023-03-20 16:55:28 +01:00
|
|
|
switch (name) {
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.VIDEO_CONVERSION: {
|
2023-03-20 16:55:28 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_VIDEO_CONVERSION, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.STORAGE_TEMPLATE_MIGRATION: {
|
2023-03-20 16:55:28 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.STORAGE_TEMPLATE_MIGRATION });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.MIGRATION: {
|
2023-09-25 17:07:21 +02:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_MIGRATION });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-09-25 17:07:21 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.SMART_SEARCH: {
|
2024-01-29 15:51:22 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_SMART_SEARCH, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-05-16 19:08:37 +02:00
|
|
|
case QueueName.DUPLICATE_DETECTION: {
|
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_DUPLICATE_DETECTION, data: { force } });
|
|
|
|
}
|
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.METADATA_EXTRACTION: {
|
2023-03-20 16:55:28 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_METADATA_EXTRACTION, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.SIDECAR: {
|
feat(server): xmp sidecar metadata (#2466)
* initial commit for XMP sidecar support
* Added support for 'missing' metadata files to include those without sidecar files, now detects sidecar files in the filesystem for media already ingested but the sidecar was created afterwards
* didn't mean to commit default log level during testing
* new sidecar logic for video metadata as well
* Added xml mimetype for sidecars only
* don't need capture group for this regex
* wrong default value reverted
* simplified the move here - keep it in the same try catch since the outcome is to move the media back anyway
* simplified setter logic
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
* simplified logic per suggestions
* sidecar is now its own queue with a discover and sync, updated UI for the new job queueing
* queue a sidecar job for every asset based on discovery or sync, though the logic is almost identical aside from linking the sidecar
* now queue sidecar jobs for each assset, though logic is mostly the same between discovery and sync
* simplified logic of filename extraction and asset instantiation
* not sure how that got deleted..
* updated code per suggestions and comments in the PR
* stat was not being used, removed the variable set
* better type checking, using in-scope variables for exif getter instead of passing in every time
* removed commented out test
* ran and resolved all lints, formats, checks, and tests
* resolved suggested change in PR
* made getExifProperty more dynamic with multiple possible args for fallbacks, fixed typo, used generic in function for better type checking
* better error handling and moving files back to positions on move or save failure
* regenerated api
* format fixes
* Added XMP documentation
* documentation typo
* Merged in main
* missed merge conflict
* more changes due to a merge
* Resolving conflicts
* added icon for sidecar jobs
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-05-25 03:59:30 +02:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_SIDECAR, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
feat(server): xmp sidecar metadata (#2466)
* initial commit for XMP sidecar support
* Added support for 'missing' metadata files to include those without sidecar files, now detects sidecar files in the filesystem for media already ingested but the sidecar was created afterwards
* didn't mean to commit default log level during testing
* new sidecar logic for video metadata as well
* Added xml mimetype for sidecars only
* don't need capture group for this regex
* wrong default value reverted
* simplified the move here - keep it in the same try catch since the outcome is to move the media back anyway
* simplified setter logic
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
* simplified logic per suggestions
* sidecar is now its own queue with a discover and sync, updated UI for the new job queueing
* queue a sidecar job for every asset based on discovery or sync, though the logic is almost identical aside from linking the sidecar
* now queue sidecar jobs for each assset, though logic is mostly the same between discovery and sync
* simplified logic of filename extraction and asset instantiation
* not sure how that got deleted..
* updated code per suggestions and comments in the PR
* stat was not being used, removed the variable set
* better type checking, using in-scope variables for exif getter instead of passing in every time
* removed commented out test
* ran and resolved all lints, formats, checks, and tests
* resolved suggested change in PR
* made getExifProperty more dynamic with multiple possible args for fallbacks, fixed typo, used generic in function for better type checking
* better error handling and moving files back to positions on move or save failure
* regenerated api
* format fixes
* Added XMP documentation
* documentation typo
* Merged in main
* missed merge conflict
* more changes due to a merge
* Resolving conflicts
* added icon for sidecar jobs
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-05-25 03:59:30 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.THUMBNAIL_GENERATION: {
|
2023-03-20 16:55:28 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_GENERATE_THUMBNAILS, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.FACE_DETECTION: {
|
2024-01-18 06:08:48 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_FACE_DETECTION, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2024-01-18 06:08:48 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.FACIAL_RECOGNITION: {
|
2024-01-18 06:08:48 +01:00
|
|
|
return this.jobRepository.queue({ name: JobName.QUEUE_FACIAL_RECOGNITION, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-05-17 19:07:17 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case QueueName.LIBRARY: {
|
2023-09-20 13:16:33 +02:00
|
|
|
return this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SCAN_ALL, data: { force } });
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-09-20 13:16:33 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
default: {
|
2023-03-20 16:55:28 +01:00
|
|
|
throw new BadRequestException(`Invalid job name: ${name}`);
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
}
|
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
|
2024-01-01 19:16:44 +01:00
|
|
|
async init(jobHandlers: Record<JobName, JobHandler>) {
|
2023-06-01 12:32:51 +02:00
|
|
|
const config = await this.configCore.getConfig();
|
|
|
|
for (const queueName of Object.values(QueueName)) {
|
2023-12-29 19:41:33 +01:00
|
|
|
let concurrency = 1;
|
2024-01-18 06:08:48 +01:00
|
|
|
|
|
|
|
if (this.isConcurrentQueue(queueName)) {
|
2023-12-29 19:41:33 +01:00
|
|
|
concurrency = config.job[queueName].concurrency;
|
|
|
|
}
|
|
|
|
|
2023-06-01 12:32:51 +02:00
|
|
|
this.logger.debug(`Registering ${queueName} with a concurrency of ${concurrency}`);
|
|
|
|
this.jobRepository.addHandler(queueName, concurrency, async (item: JobItem): Promise<void> => {
|
|
|
|
const { name, data } = item;
|
|
|
|
|
2024-03-25 04:02:04 +01:00
|
|
|
const queueMetric = `immich.queues.${snakeCase(queueName)}.active`;
|
2024-03-26 00:15:11 +01:00
|
|
|
this.metricRepository.jobs.addToGauge(queueMetric, 1);
|
2024-03-25 04:02:04 +01:00
|
|
|
|
2023-06-01 12:32:51 +02:00
|
|
|
try {
|
|
|
|
const handler = jobHandlers[name];
|
2024-03-15 14:16:54 +01:00
|
|
|
const status = await handler(data);
|
2024-03-25 04:02:04 +01:00
|
|
|
const jobMetric = `immich.jobs.${name.replaceAll('-', '_')}.${status}`;
|
2024-03-26 00:15:11 +01:00
|
|
|
this.metricRepository.jobs.addToCounter(jobMetric, 1);
|
2024-03-15 14:16:54 +01:00
|
|
|
if (status === JobStatus.SUCCESS || status == JobStatus.SKIPPED) {
|
2023-06-01 12:32:51 +02:00
|
|
|
await this.onDone(item);
|
|
|
|
}
|
|
|
|
} catch (error: Error | any) {
|
2023-09-20 13:16:33 +02:00
|
|
|
this.logger.error(`Unable to run job handler (${queueName}/${name}): ${error}`, error?.stack, data);
|
2024-03-25 04:02:04 +01:00
|
|
|
} finally {
|
2024-03-26 00:15:11 +01:00
|
|
|
this.metricRepository.jobs.addToGauge(queueMetric, -1);
|
2023-06-01 12:32:51 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.configCore.config$.subscribe((config) => {
|
2024-01-18 06:08:48 +01:00
|
|
|
this.logger.debug(`Updating queue concurrency settings`);
|
2023-06-01 12:32:51 +02:00
|
|
|
for (const queueName of Object.values(QueueName)) {
|
2023-12-29 19:41:33 +01:00
|
|
|
let concurrency = 1;
|
2024-01-18 06:08:48 +01:00
|
|
|
if (this.isConcurrentQueue(queueName)) {
|
2023-12-29 19:41:33 +01:00
|
|
|
concurrency = config.job[queueName].concurrency;
|
|
|
|
}
|
2023-06-01 12:32:51 +02:00
|
|
|
this.logger.debug(`Setting ${queueName} concurrency to ${concurrency}`);
|
|
|
|
this.jobRepository.setConcurrency(queueName, concurrency);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-18 06:08:48 +01:00
|
|
|
private isConcurrentQueue(name: QueueName): name is ConcurrentQueueName {
|
2024-05-16 19:08:37 +02:00
|
|
|
return ![
|
|
|
|
QueueName.FACIAL_RECOGNITION,
|
|
|
|
QueueName.STORAGE_TEMPLATE_MIGRATION,
|
|
|
|
QueueName.DUPLICATE_DETECTION,
|
|
|
|
].includes(name);
|
2024-01-18 06:08:48 +01:00
|
|
|
}
|
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
async handleNightlyJobs() {
|
2024-01-01 21:45:42 +01:00
|
|
|
await this.jobRepository.queueAll([
|
|
|
|
{ name: JobName.ASSET_DELETION_CHECK },
|
|
|
|
{ name: JobName.USER_DELETE_CHECK },
|
|
|
|
{ name: JobName.PERSON_CLEANUP },
|
|
|
|
{ name: JobName.QUEUE_GENERATE_THUMBNAILS, data: { force: false } },
|
|
|
|
{ name: JobName.CLEAN_OLD_AUDIT_LOGS },
|
2024-01-13 01:43:36 +01:00
|
|
|
{ name: JobName.USER_SYNC_USAGE },
|
2024-01-25 07:27:39 +01:00
|
|
|
{ name: JobName.QUEUE_FACIAL_RECOGNITION, data: { force: false } },
|
2024-04-27 22:45:16 +02:00
|
|
|
{ name: JobName.CLEAN_OLD_SESSION_TOKENS },
|
2024-01-01 21:45:42 +01:00
|
|
|
]);
|
2023-05-26 21:43:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue follow up jobs
|
|
|
|
*/
|
2023-06-01 22:07:45 +02:00
|
|
|
private async onDone(item: JobItem) {
|
2023-05-26 21:43:24 +02:00
|
|
|
switch (item.name) {
|
|
|
|
case JobName.SIDECAR_SYNC:
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.SIDECAR_DISCOVERY: {
|
2023-06-01 22:07:45 +02:00
|
|
|
await this.jobRepository.queue({ name: JobName.METADATA_EXTRACTION, data: item.data });
|
2023-05-26 21:43:24 +02:00
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.SIDECAR_WRITE: {
|
2023-11-30 04:52:28 +01:00
|
|
|
await this.jobRepository.queue({
|
|
|
|
name: JobName.METADATA_EXTRACTION,
|
|
|
|
data: { id: item.data.id, source: 'sidecar-write' },
|
|
|
|
});
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-11-30 04:52:28 +01:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.METADATA_EXTRACTION: {
|
2023-11-30 04:52:28 +01:00
|
|
|
if (item.data.source === 'sidecar-write') {
|
2024-03-14 06:58:09 +01:00
|
|
|
const [asset] = await this.assetRepository.getByIdsWithAllRelations([item.data.id]);
|
2023-11-30 04:52:28 +01:00
|
|
|
if (asset) {
|
2024-03-22 23:24:02 +01:00
|
|
|
this.eventRepository.clientSend(ClientEvent.ASSET_UPDATE, asset.ownerId, mapAsset(asset));
|
2023-11-30 04:52:28 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-16 03:34:57 +02:00
|
|
|
await this.jobRepository.queue({ name: JobName.LINK_LIVE_PHOTOS, data: item.data });
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-08-16 03:34:57 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.LINK_LIVE_PHOTOS: {
|
2023-05-26 21:43:24 +02:00
|
|
|
await this.jobRepository.queue({ name: JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE, data: item.data });
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
|
2023-05-27 23:49:57 +02:00
|
|
|
if (item.data.source === 'upload') {
|
2024-04-02 06:56:56 +02:00
|
|
|
await this.jobRepository.queue({ name: JobName.GENERATE_PREVIEW, data: item.data });
|
2023-05-27 23:49:57 +02:00
|
|
|
}
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-05-27 23:49:57 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
case JobName.GENERATE_PERSON_THUMBNAIL: {
|
2023-10-06 22:48:11 +02:00
|
|
|
const { id } = item.data;
|
|
|
|
const person = await this.personRepository.getById(id);
|
|
|
|
if (person) {
|
2024-03-22 23:24:02 +01:00
|
|
|
this.eventRepository.clientSend(ClientEvent.PERSON_THUMBNAIL, person.ownerId, person.id);
|
2023-10-06 22:48:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-10-06 22:48:11 +02:00
|
|
|
|
2024-04-02 06:56:56 +02:00
|
|
|
case JobName.GENERATE_PREVIEW: {
|
2024-01-01 21:45:42 +01:00
|
|
|
const jobs: JobItem[] = [
|
2024-04-02 06:56:56 +02:00
|
|
|
{ name: JobName.GENERATE_THUMBNAIL, data: item.data },
|
|
|
|
{ name: JobName.GENERATE_THUMBHASH, data: item.data },
|
2024-01-01 21:45:42 +01:00
|
|
|
];
|
2023-05-26 21:43:24 +02:00
|
|
|
|
2024-02-29 05:23:21 +01:00
|
|
|
if (item.data.source === 'upload') {
|
|
|
|
jobs.push({ name: JobName.SMART_SEARCH, data: item.data }, { name: JobName.FACE_DETECTION, data: item.data });
|
|
|
|
|
|
|
|
const [asset] = await this.assetRepository.getByIds([item.data.id]);
|
|
|
|
if (asset) {
|
|
|
|
if (asset.type === AssetType.VIDEO) {
|
|
|
|
jobs.push({ name: JobName.VIDEO_CONVERSION, data: item.data });
|
|
|
|
} else if (asset.livePhotoVideoId) {
|
|
|
|
jobs.push({ name: JobName.VIDEO_CONVERSION, data: { id: asset.livePhotoVideoId } });
|
|
|
|
}
|
2023-07-05 07:36:16 +02:00
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
}
|
2024-01-01 21:45:42 +01:00
|
|
|
|
|
|
|
await this.jobRepository.queueAll(jobs);
|
2023-05-26 21:43:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-10-06 22:48:11 +02:00
|
|
|
|
2024-04-02 06:56:56 +02:00
|
|
|
case JobName.GENERATE_THUMBNAIL: {
|
2023-10-06 22:48:11 +02:00
|
|
|
if (item.data.source !== 'upload') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-03-14 06:58:09 +01:00
|
|
|
const [asset] = await this.assetRepository.getByIdsWithAllRelations([item.data.id]);
|
2023-12-03 23:35:22 +01:00
|
|
|
|
|
|
|
// Only live-photo motion part will be marked as not visible immediately on upload. Skip notifying clients
|
|
|
|
if (asset && asset.isVisible) {
|
2024-03-22 23:24:02 +01:00
|
|
|
this.eventRepository.clientSend(ClientEvent.UPLOAD_SUCCESS, asset.ownerId, mapAsset(asset));
|
2023-10-06 22:48:11 +02:00
|
|
|
}
|
2024-01-18 06:08:48 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-08 23:49:39 +01:00
|
|
|
|
2024-05-16 19:08:37 +02:00
|
|
|
case JobName.SMART_SEARCH: {
|
|
|
|
if (item.data.source === 'upload') {
|
|
|
|
await this.jobRepository.queue({ name: JobName.DUPLICATE_DETECTION, data: item.data });
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-03-08 23:49:39 +01:00
|
|
|
case JobName.USER_DELETION: {
|
2024-03-22 23:24:02 +01:00
|
|
|
this.eventRepository.clientBroadcast(ClientEvent.USER_DELETE, item.data.id);
|
2024-03-08 23:49:39 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-20 16:55:28 +01:00
|
|
|
}
|