mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 10:08:42 +03:00
refactor: job events (#23161)
This commit is contained in:
@@ -17,7 +17,7 @@ import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { NotificationDto } from 'src/dtos/notification.dto';
|
||||
import { ReleaseNotification, ServerVersionResponseDto } from 'src/dtos/server.dto';
|
||||
import { SyncAssetExifV1, SyncAssetV1 } from 'src/dtos/sync.dto';
|
||||
import { ImmichWorker, MetadataKey, QueueName, UserAvatarColor, UserStatus } from 'src/enum';
|
||||
import { ImmichWorker, JobStatus, MetadataKey, QueueName, UserAvatarColor, UserStatus } from 'src/enum';
|
||||
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||
import { JobItem, JobSource } from 'src/types';
|
||||
@@ -66,8 +66,19 @@ type EventMap = {
|
||||
AssetDeleteAll: [{ assetIds: string[]; userId: string }];
|
||||
AssetRestoreAll: [{ assetIds: string[]; userId: string }];
|
||||
|
||||
/** a worker receives a job and emits this event to run it */
|
||||
JobRun: [QueueName, JobItem];
|
||||
/** job pre-hook */
|
||||
JobStart: [QueueName, JobItem];
|
||||
JobFailed: [{ job: JobItem; error: Error | any }];
|
||||
/** job post-hook */
|
||||
JobComplete: [QueueName, JobItem];
|
||||
/** job finishes without error */
|
||||
JobSuccess: [JobSuccessEvent];
|
||||
/** job finishes with error */
|
||||
JobError: [JobErrorEvent];
|
||||
|
||||
// queue events
|
||||
QueueStart: [QueueStartEvent];
|
||||
|
||||
// session events
|
||||
SessionDelete: [{ sessionId: string }];
|
||||
@@ -90,6 +101,13 @@ type EventMap = {
|
||||
WebsocketConnect: [{ userId: string }];
|
||||
};
|
||||
|
||||
type JobSuccessEvent = { job: JobItem; response?: JobStatus };
|
||||
type JobErrorEvent = { job: JobItem; error: Error | any };
|
||||
|
||||
type QueueStartEvent = {
|
||||
name: QueueName;
|
||||
};
|
||||
|
||||
type UserEvent = {
|
||||
name: string;
|
||||
id: string;
|
||||
|
||||
@@ -89,7 +89,7 @@ export class JobRepository {
|
||||
this.logger.debug(`Starting worker for queue: ${queueName}`);
|
||||
this.workers[queueName] = new Worker(
|
||||
queueName,
|
||||
(job) => this.eventRepository.emit('JobStart', queueName, job as JobItem),
|
||||
(job) => this.eventRepository.emit('JobRun', queueName, job as JobItem),
|
||||
{ ...bull.config, concurrency: 1 },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user