refactor(server): job discovery (#13838)

refactor(server): job discorvery
This commit is contained in:
Jason Rasmussen 2024-10-31 13:42:58 -04:00 committed by GitHub
parent 0130052de5
commit 5b2cd704d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 323 additions and 376 deletions

View file

@ -1,6 +1,7 @@
import { BadRequestException } from '@nestjs/common';
import _ from 'lodash';
import { DateTime, Duration } from 'luxon';
import { OnJob } from 'src/decorators';
import {
AssetResponseDto,
MemoryLaneResponseDto,
@ -21,12 +22,13 @@ import { MemoryLaneDto } from 'src/dtos/search.dto';
import { AssetEntity } from 'src/entities/asset.entity';
import { AssetStatus, Permission } from 'src/enum';
import {
IAssetDeleteJob,
ISidecarWriteJob,
JOBS_ASSET_PAGINATION_SIZE,
JobItem,
JobName,
JobOf,
JobStatus,
QueueName,
} from 'src/interfaces/job.interface';
import { BaseService } from 'src/services/base.service';
import { getAssetFiles, getMyPartnerIds, onAfterUnlink, onBeforeLink, onBeforeUnlink } from 'src/utils/asset.util';
@ -186,6 +188,7 @@ export class AssetService extends BaseService {
await this.assetRepository.updateAll(ids, options);
}
@OnJob({ name: JobName.ASSET_DELETION_CHECK, queue: QueueName.BACKGROUND_TASK })
async handleAssetDeletionCheck(): Promise<JobStatus> {
const config = await this.getConfig({ withCache: false });
const trashedDays = config.trash.enabled ? config.trash.days : 0;
@ -211,7 +214,8 @@ export class AssetService extends BaseService {
return JobStatus.SUCCESS;
}
async handleAssetDeletion(job: IAssetDeleteJob): Promise<JobStatus> {
@OnJob({ name: JobName.ASSET_DELETION, queue: QueueName.BACKGROUND_TASK })
async handleAssetDeletion(job: JobOf<JobName.ASSET_DELETION>): Promise<JobStatus> {
const { id, deleteOnDisk } = job;
const asset = await this.assetRepository.getById(id, {