Skip to content

Commit

Permalink
feat: add job ids
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Feb 7, 2025
1 parent c5360e7 commit c3bba12
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 0 additions & 1 deletion server/src/interfaces/job.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export interface IAssetDeleteJob extends IEntityJob {
}

export interface ILibraryFileJob extends IEntityJob {
ownerId: string;
assetPath: string;
}

Expand Down
25 changes: 22 additions & 3 deletions server/src/repositories/job.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,37 @@ export class JobRepository implements IJobRepository {

private getJobOptions(item: JobItem): JobsOptions | null {
switch (item.name) {
case JobName.LIBRARY_QUEUE_SYNC_ASSETS:
case JobName.LIBRARY_QUEUE_SYNC_FILES:
case JobName.LIBRARY_SYNC_ASSET:
case JobName.LIBRARY_DELETE:
case JobName.SIDECAR_SYNC:
case JobName.SIDECAR_DISCOVERY:
case JobName.GENERATE_THUMBNAILS:
case JobName.METADATA_EXTRACTION:
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
return { jobId: `${item.data.id}-${item.name}` };
}
case JobName.SIDECAR_DISCOVERY: {
return { jobId: `${item.data.id}-${item.data.source}` };
}
case JobName.LIBRARY_SYNC_FILE: {
return { jobId: `${item.data.id}-${item.data.assetPath}` };
}
case JobName.NOTIFY_ALBUM_UPDATE: {
return { jobId: item.data.id, delay: item.data?.delay };
}
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
return { jobId: item.data.id };
}
case JobName.GENERATE_PERSON_THUMBNAIL: {
return { priority: 1 };
}
case JobName.QUEUE_FACIAL_RECOGNITION: {
return { jobId: JobName.QUEUE_FACIAL_RECOGNITION };
}
case JobName.LIBRARY_QUEUE_SYNC_ALL:
case JobName.LIBRARY_QUEUE_CLEANUP: {
// These jobs are globally unique and should only have one instance running at a time
return { jobId: item.name };
}
default: {
return null;
}
Expand Down
7 changes: 5 additions & 2 deletions server/src/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class LibraryService extends BaseService {
data: {
id,
assetPath,
ownerId,
},
})),
);
Expand Down Expand Up @@ -401,7 +400,7 @@ export class LibraryService extends BaseService {
const mtime = stat.mtime;

asset = await this.assetRepository.create({
ownerId: job.ownerId,
ownerId: library.ownerId,
libraryId: job.id,
checksum: pathHash,
originalPath: assetPath,
Expand Down Expand Up @@ -433,12 +432,16 @@ export class LibraryService extends BaseService {
async queueScan(id: string) {
await this.findOrFail(id);

// We purge any existing scan jobs for this library
await this.jobRepository.removeJob(id, JobName.LIBRARY_QUEUE_SYNC_FILES);
await this.jobRepository.queue({
name: JobName.LIBRARY_QUEUE_SYNC_FILES,
data: {
id,
},
});

await this.jobRepository.removeJob(id, JobName.LIBRARY_QUEUE_SYNC_ASSETS);
await this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ASSETS, data: { id } });
}

Expand Down

0 comments on commit c3bba12

Please sign in to comment.