|
@@ -1,19 +1,8 @@
|
|
|
-import {
|
|
|
- exifExtractionProcessorName,
|
|
|
- generateJPEGThumbnailProcessorName,
|
|
|
- IMetadataExtractionJob,
|
|
|
- IThumbnailGenerationJob,
|
|
|
- IVideoTranscodeJob,
|
|
|
- MachineLearningJobNameEnum,
|
|
|
- QueueNameEnum,
|
|
|
- templateMigrationProcessorName,
|
|
|
- videoMetadataExtractionProcessorName,
|
|
|
-} from '@app/job';
|
|
|
+import { IMetadataExtractionJob, IThumbnailGenerationJob, IVideoTranscodeJob, QueueName, JobName } from '@app/job';
|
|
|
import { InjectQueue } from '@nestjs/bull';
|
|
|
import { Queue } from 'bull';
|
|
|
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
|
|
import { AllJobStatusResponseDto } from './response-dto/all-job-status-response.dto';
|
|
|
-import { randomUUID } from 'crypto';
|
|
|
import { IAssetRepository } from '../asset/asset-repository';
|
|
|
import { AssetType } from '@app/infra';
|
|
|
import { GetJobDto, JobId } from './dto/get-job.dto';
|
|
@@ -24,20 +13,20 @@ import { StorageService } from '@app/storage';
|
|
|
@Injectable()
|
|
|
export class JobService {
|
|
|
constructor(
|
|
|
- @InjectQueue(QueueNameEnum.THUMBNAIL_GENERATION)
|
|
|
+ @InjectQueue(QueueName.THUMBNAIL_GENERATION)
|
|
|
private thumbnailGeneratorQueue: Queue<IThumbnailGenerationJob>,
|
|
|
|
|
|
- @InjectQueue(QueueNameEnum.METADATA_EXTRACTION)
|
|
|
+ @InjectQueue(QueueName.METADATA_EXTRACTION)
|
|
|
private metadataExtractionQueue: Queue<IMetadataExtractionJob>,
|
|
|
|
|
|
- @InjectQueue(QueueNameEnum.VIDEO_CONVERSION)
|
|
|
+ @InjectQueue(QueueName.VIDEO_CONVERSION)
|
|
|
private videoConversionQueue: Queue<IVideoTranscodeJob>,
|
|
|
|
|
|
- @InjectQueue(QueueNameEnum.MACHINE_LEARNING)
|
|
|
+ @InjectQueue(QueueName.MACHINE_LEARNING)
|
|
|
private machineLearningQueue: Queue<IMachineLearningJob>,
|
|
|
|
|
|
- @InjectQueue(QueueNameEnum.STORAGE_MIGRATION)
|
|
|
- private storageMigrationQueue: Queue,
|
|
|
+ @InjectQueue(QueueName.CONFIG)
|
|
|
+ private configQueue: Queue,
|
|
|
|
|
|
@Inject(IAssetRepository)
|
|
|
private _assetRepository: IAssetRepository,
|
|
@@ -47,7 +36,7 @@ export class JobService {
|
|
|
this.thumbnailGeneratorQueue.empty();
|
|
|
this.metadataExtractionQueue.empty();
|
|
|
this.videoConversionQueue.empty();
|
|
|
- this.storageMigrationQueue.empty();
|
|
|
+ this.configQueue.empty();
|
|
|
}
|
|
|
|
|
|
async startJob(jobDto: GetJobDto): Promise<number> {
|
|
@@ -72,7 +61,7 @@ export class JobService {
|
|
|
const metadataExtractionJobCount = await this.metadataExtractionQueue.getJobCounts();
|
|
|
const videoConversionJobCount = await this.videoConversionQueue.getJobCounts();
|
|
|
const machineLearningJobCount = await this.machineLearningQueue.getJobCounts();
|
|
|
- const storageMigrationJobCount = await this.storageMigrationQueue.getJobCounts();
|
|
|
+ const storageMigrationJobCount = await this.configQueue.getJobCounts();
|
|
|
|
|
|
const response = new AllJobStatusResponseDto();
|
|
|
response.isThumbnailGenerationActive = Boolean(thumbnailGeneratorJobCount.waiting);
|
|
@@ -108,8 +97,8 @@ export class JobService {
|
|
|
}
|
|
|
|
|
|
if (query.jobId === JobId.STORAGE_TEMPLATE_MIGRATION) {
|
|
|
- response.isActive = Boolean((await this.storageMigrationQueue.getJobCounts()).waiting);
|
|
|
- response.queueCount = await this.storageMigrationQueue.getJobCounts();
|
|
|
+ response.isActive = Boolean((await this.configQueue.getJobCounts()).waiting);
|
|
|
+ response.queueCount = await this.configQueue.getJobCounts();
|
|
|
}
|
|
|
|
|
|
return response;
|
|
@@ -130,7 +119,7 @@ export class JobService {
|
|
|
this.machineLearningQueue.empty();
|
|
|
return 0;
|
|
|
case JobId.STORAGE_TEMPLATE_MIGRATION:
|
|
|
- this.storageMigrationQueue.empty();
|
|
|
+ this.configQueue.empty();
|
|
|
return 0;
|
|
|
default:
|
|
|
throw new BadRequestException('Invalid job id');
|
|
@@ -147,7 +136,7 @@ export class JobService {
|
|
|
const assetsWithNoThumbnail = await this._assetRepository.getAssetWithNoThumbnail();
|
|
|
|
|
|
for (const asset of assetsWithNoThumbnail) {
|
|
|
- await this.thumbnailGeneratorQueue.add(generateJPEGThumbnailProcessorName, { asset }, { jobId: randomUUID() });
|
|
|
+ await this.thumbnailGeneratorQueue.add(JobName.GENERATE_JPEG_THUMBNAIL, { asset });
|
|
|
}
|
|
|
|
|
|
return assetsWithNoThumbnail.length;
|
|
@@ -163,17 +152,9 @@ export class JobService {
|
|
|
const assetsWithNoExif = await this._assetRepository.getAssetWithNoEXIF();
|
|
|
for (const asset of assetsWithNoExif) {
|
|
|
if (asset.type === AssetType.VIDEO) {
|
|
|
- await this.metadataExtractionQueue.add(
|
|
|
- videoMetadataExtractionProcessorName,
|
|
|
- { asset, fileName: asset.id },
|
|
|
- { jobId: randomUUID() },
|
|
|
- );
|
|
|
+ await this.metadataExtractionQueue.add(JobName.EXTRACT_VIDEO_METADATA, { asset, fileName: asset.id });
|
|
|
} else {
|
|
|
- await this.metadataExtractionQueue.add(
|
|
|
- exifExtractionProcessorName,
|
|
|
- { asset, fileName: asset.id },
|
|
|
- { jobId: randomUUID() },
|
|
|
- );
|
|
|
+ await this.metadataExtractionQueue.add(JobName.EXIF_EXTRACTION, { asset, fileName: asset.id });
|
|
|
}
|
|
|
}
|
|
|
return assetsWithNoExif.length;
|
|
@@ -189,25 +170,21 @@ export class JobService {
|
|
|
const assetWithNoSmartInfo = await this._assetRepository.getAssetWithNoSmartInfo();
|
|
|
|
|
|
for (const asset of assetWithNoSmartInfo) {
|
|
|
- await this.machineLearningQueue.add(MachineLearningJobNameEnum.IMAGE_TAGGING, { asset }, { jobId: randomUUID() });
|
|
|
- await this.machineLearningQueue.add(
|
|
|
- MachineLearningJobNameEnum.OBJECT_DETECTION,
|
|
|
- { asset },
|
|
|
- { jobId: randomUUID() },
|
|
|
- );
|
|
|
+ await this.machineLearningQueue.add(JobName.IMAGE_TAGGING, { asset });
|
|
|
+ await this.machineLearningQueue.add(JobName.OBJECT_DETECTION, { asset });
|
|
|
}
|
|
|
|
|
|
return assetWithNoSmartInfo.length;
|
|
|
}
|
|
|
|
|
|
async runStorageMigration() {
|
|
|
- const jobCount = await this.storageMigrationQueue.getJobCounts();
|
|
|
+ const jobCount = await this.configQueue.getJobCounts();
|
|
|
|
|
|
if (jobCount.active > 0) {
|
|
|
throw new BadRequestException('Storage migration job is already running');
|
|
|
}
|
|
|
|
|
|
- await this.storageMigrationQueue.add(templateMigrationProcessorName, {}, { jobId: randomUUID() });
|
|
|
+ await this.configQueue.add(JobName.TEMPLATE_MIGRATION, {});
|
|
|
|
|
|
return 1;
|
|
|
}
|