Refactor shelves UI and jobs

This commit is contained in:
Rob Walsh
2026-02-27 15:46:10 -07:00
parent cfe780c6f0
commit 41d45d1210
12 changed files with 511 additions and 619 deletions
+15 -54
View File
@@ -26,8 +26,7 @@ export type JobType =
| 'retry_failed_imports'
| 'cleanup_seeded_torrents'
| 'monitor_rss_feeds'
| 'sync_goodreads_shelves'
| 'sync_hardcover_shelves'
| 'sync_reading_shelves'
| 'send_notification'
// Ebook-specific job types
| 'search_ebook'
@@ -106,15 +105,10 @@ export interface CleanupSeededTorrentsPayload extends JobPayload {
scheduledJobId?: string;
}
export interface SyncGoodreadsShelvesPayload extends JobPayload {
scheduledJobId?: string;
shelfId?: string;
maxLookupsPerShelf?: number;
}
export interface SyncHardcoverShelvesPayload extends JobPayload {
export interface SyncShelvesPayload extends JobPayload {
scheduledJobId?: string;
shelfId?: string;
shelfType?: 'goodreads' | 'hardcover';
maxLookupsPerShelf?: number;
}
@@ -447,30 +441,16 @@ export class JobQueueService {
);
this.queue.process(
'sync_goodreads_shelves',
'sync_reading_shelves',
1,
async (job: BullJob<SyncGoodreadsShelvesPayload>) => {
const { processSyncGoodreadsShelves } =
await import('../processors/sync-goodreads-shelves.processor');
async (job: BullJob<SyncShelvesPayload>) => {
const { processSyncShelves } =
await import('../processors/sync-shelves.processor');
const payloadWithJobId = await this.ensureJobRecord(
job,
'sync_goodreads_shelves',
'sync_reading_shelves',
);
return await processSyncGoodreadsShelves(payloadWithJobId);
},
);
this.queue.process(
'sync_hardcover_shelves',
1,
async (job: BullJob<SyncHardcoverShelvesPayload>) => {
const { processSyncHardcoverShelves } =
await import('../processors/sync-hardcover-shelves.processor');
const payloadWithJobId = await this.ensureJobRecord(
job,
'sync_hardcover_shelves',
);
return await processSyncHardcoverShelves(payloadWithJobId);
return await processSyncShelves(payloadWithJobId);
},
);
@@ -875,41 +855,22 @@ export class JobQueueService {
}
/**
* Add sync Goodreads shelves job
* Add sync reading shelves job
*/
async addSyncGoodreadsShelvesJob(
async addSyncShelvesJob(
scheduledJobId?: string,
shelfId?: string,
shelfType?: 'goodreads' | 'hardcover',
maxLookupsPerShelf?: number,
): Promise<string> {
return await this.addJob(
'sync_goodreads_shelves',
'sync_reading_shelves',
{
scheduledJobId,
shelfId,
shelfType,
maxLookupsPerShelf,
} as SyncGoodreadsShelvesPayload,
{
priority: 7,
},
);
}
/**
* Add sync Hardcover shelves job
*/
async addSyncHardcoverShelvesJob(
scheduledJobId?: string,
shelfId?: string,
maxLookupsPerShelf?: number,
): Promise<string> {
return await this.addJob(
'sync_hardcover_shelves',
{
scheduledJobId,
shelfId,
maxLookupsPerShelf,
} as SyncHardcoverShelvesPayload,
} as SyncShelvesPayload,
{
priority: 7,
},
+41 -26
View File
@@ -18,8 +18,7 @@ export type ScheduledJobType =
| 'retry_failed_imports'
| 'cleanup_seeded_torrents'
| 'monitor_rss_feeds'
| 'sync_goodreads_shelves'
| 'sync_hardcover_shelves';
| 'sync_reading_shelves';
export interface ScheduledJob {
id: string;
@@ -68,6 +67,9 @@ export class SchedulerService {
});
}
// Clean up deprecated scheduled jobs
await this.cleanupDeprecatedJobs();
// Create default jobs if they don't exist
await this.ensureDefaultJobs();
@@ -136,15 +138,8 @@ export class SchedulerService {
payload: {},
},
{
name: 'Sync Goodreads Shelves',
type: 'sync_goodreads_shelves' as ScheduledJobType,
schedule: '0 */6 * * *', // Every 6 hours
enabled: true, // Enable by default
payload: {},
},
{
name: 'Sync Hardcover Lists',
type: 'sync_hardcover_shelves' as ScheduledJobType,
name: 'Sync Reading Shelves',
type: 'sync_reading_shelves' as ScheduledJobType,
schedule: '0 */6 * * *', // Every 6 hours
enabled: true, // Enable by default
payload: {},
@@ -187,6 +182,36 @@ export class SchedulerService {
}
}
/**
* Remove any old jobs that are no longer supported
*/
private async cleanupDeprecatedJobs(): Promise<void> {
try {
const deprecatedTypes = [
'sync_goodreads_shelves',
'sync_hardcover_shelves',
];
const obsoleteJobs = await prisma.scheduledJob.findMany({
where: { type: { in: deprecatedTypes } },
});
for (const job of obsoleteJobs) {
if (job.enabled) {
await this.unscheduleJob(job);
}
await prisma.scheduledJob.delete({ where: { id: job.id } });
logger.info(
`Removed deprecated scheduled job: ${job.name} (${job.type})`,
);
}
} catch (error) {
logger.error('Failed to cleanup deprecated scheduled jobs', {
error: error instanceof Error ? error.message : String(error),
});
}
}
/**
* Schedule all enabled jobs
*/
@@ -374,11 +399,8 @@ export class SchedulerService {
case 'monitor_rss_feeds':
bullJobId = await this.triggerMonitorRssFeeds(job);
break;
case 'sync_goodreads_shelves':
bullJobId = await this.triggerSyncGoodreadsShelves(job);
break;
case 'sync_hardcover_shelves':
bullJobId = await this.triggerSyncHardcoverShelves(job);
case 'sync_reading_shelves':
bullJobId = await this.triggerSyncShelves(job);
break;
default:
throw new Error(`Unknown job type: ${job.type}`);
@@ -663,17 +685,10 @@ export class SchedulerService {
}
/**
* Trigger Goodreads shelves sync
* Trigger Reading shelves sync
*/
private async triggerSyncGoodreadsShelves(job: any): Promise<string> {
return await this.jobQueue.addSyncGoodreadsShelvesJob(job.id);
}
/**
* Trigger Hardcover lists sync
*/
private async triggerSyncHardcoverShelves(job: any): Promise<string> {
return await this.jobQueue.addSyncHardcoverShelvesJob(job.id);
private async triggerSyncShelves(job: any): Promise<string> {
return await this.jobQueue.addSyncShelvesJob(job.id);
}
}