2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import type { ObjectStorageJobData } from '@/queue/types.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
import type { Config } from '@/config.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { CleanRemoteFilesProcessorService } from './processors/CleanRemoteFilesProcessorService.js';
|
|
|
|
import { DeleteFileProcessorService } from './processors/DeleteFileProcessorService.js';
|
|
|
|
import type Bull from 'bull';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ObjectStorageQueueProcessorsService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.config)
|
|
|
|
private config: Config,
|
|
|
|
|
|
|
|
private deleteFileProcessorService: DeleteFileProcessorService,
|
|
|
|
private cleanRemoteFilesProcessorService: CleanRemoteFilesProcessorService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public start(q: Bull.Queue) {
|
|
|
|
const jobs = {
|
2022-09-23 00:21:31 +03:00
|
|
|
deleteFile: (job) => this.deleteFileProcessorService.process(job),
|
2022-09-24 00:45:44 +03:00
|
|
|
cleanRemoteFiles: (job, done) => this.cleanRemoteFilesProcessorService.process(job, done),
|
2022-09-17 21:27:08 +03:00
|
|
|
} as Record<string, Bull.ProcessCallbackFunction<ObjectStorageJobData | Bull.ProcessPromiseFunction<ObjectStorageJobData>>>;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(jobs)) {
|
|
|
|
q.process(k, 16, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|