Skip to content

Commit c3bba12

Browse files
committed
feat: add job ids
1 parent c5360e7 commit c3bba12

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

server/src/interfaces/job.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export interface IAssetDeleteJob extends IEntityJob {
144144
}
145145

146146
export interface ILibraryFileJob extends IEntityJob {
147-
ownerId: string;
148147
assetPath: string;
149148
}
150149

server/src/repositories/job.repository.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,37 @@ export class JobRepository implements IJobRepository {
216216

217217
private getJobOptions(item: JobItem): JobsOptions | null {
218218
switch (item.name) {
219+
case JobName.LIBRARY_QUEUE_SYNC_ASSETS:
220+
case JobName.LIBRARY_QUEUE_SYNC_FILES:
221+
case JobName.LIBRARY_SYNC_ASSET:
222+
case JobName.LIBRARY_DELETE:
223+
case JobName.SIDECAR_SYNC:
224+
case JobName.SIDECAR_DISCOVERY:
225+
case JobName.GENERATE_THUMBNAILS:
226+
case JobName.METADATA_EXTRACTION:
227+
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
228+
return { jobId: `${item.data.id}-${item.name}` };
229+
}
230+
case JobName.SIDECAR_DISCOVERY: {
231+
return { jobId: `${item.data.id}-${item.data.source}` };
232+
}
233+
case JobName.LIBRARY_SYNC_FILE: {
234+
return { jobId: `${item.data.id}-${item.data.assetPath}` };
235+
}
219236
case JobName.NOTIFY_ALBUM_UPDATE: {
220237
return { jobId: item.data.id, delay: item.data?.delay };
221238
}
222-
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
223-
return { jobId: item.data.id };
224-
}
225239
case JobName.GENERATE_PERSON_THUMBNAIL: {
226240
return { priority: 1 };
227241
}
228242
case JobName.QUEUE_FACIAL_RECOGNITION: {
229243
return { jobId: JobName.QUEUE_FACIAL_RECOGNITION };
230244
}
245+
case JobName.LIBRARY_QUEUE_SYNC_ALL:
246+
case JobName.LIBRARY_QUEUE_CLEANUP: {
247+
// These jobs are globally unique and should only have one instance running at a time
248+
return { jobId: item.name };
249+
}
231250
default: {
232251
return null;
233252
}

server/src/services/library.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ export class LibraryService extends BaseService {
235235
data: {
236236
id,
237237
assetPath,
238-
ownerId,
239238
},
240239
})),
241240
);
@@ -401,7 +400,7 @@ export class LibraryService extends BaseService {
401400
const mtime = stat.mtime;
402401

403402
asset = await this.assetRepository.create({
404-
ownerId: job.ownerId,
403+
ownerId: library.ownerId,
405404
libraryId: job.id,
406405
checksum: pathHash,
407406
originalPath: assetPath,
@@ -433,12 +432,16 @@ export class LibraryService extends BaseService {
433432
async queueScan(id: string) {
434433
await this.findOrFail(id);
435434

435+
// We purge any existing scan jobs for this library
436+
await this.jobRepository.removeJob(id, JobName.LIBRARY_QUEUE_SYNC_FILES);
436437
await this.jobRepository.queue({
437438
name: JobName.LIBRARY_QUEUE_SYNC_FILES,
438439
data: {
439440
id,
440441
},
441442
});
443+
444+
await this.jobRepository.removeJob(id, JobName.LIBRARY_QUEUE_SYNC_ASSETS);
442445
await this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ASSETS, data: { id } });
443446
}
444447

0 commit comments

Comments
 (0)