feat: initial user list (no edit/delete yet) and job schedules

This commit is contained in:
sct
2020-11-05 10:45:51 +00:00
parent 320432657e
commit 24a0423f3b
10 changed files with 213 additions and 7 deletions

View File

@@ -67,7 +67,8 @@ class JobPlexSync {
existing.status = MediaStatus.AVAILABLE;
mediaRepository.save(existing);
this.log(
`Request for ${metadata.title} exists. Setting status AVAILABLE`
`Request for ${metadata.title} exists. Setting status AVAILABLE`,
'info'
);
} else {
newMedia.status = MediaStatus.AVAILABLE;
@@ -90,7 +91,8 @@ class JobPlexSync {
existing.status = MediaStatus.AVAILABLE;
await mediaRepository.save(existing);
this.log(
`Request for ${plexitem.title} exists. Setting status AVAILABLE`
`Request for ${plexitem.title} exists. Setting status AVAILABLE`,
'info'
);
} else if (tmdbMovie) {
const newMedia = new Media();
@@ -139,8 +141,11 @@ class JobPlexSync {
}
}
private log(message: string): void {
logger.info(message, { label: 'Plex Sync' });
private log(
message: string,
level: 'info' | 'error' | 'debug' = 'debug'
): void {
logger[level](message, { label: 'Plex Sync' });
}
public async run(): Promise<void> {
@@ -160,7 +165,7 @@ class JobPlexSync {
for (const library of this.libraries) {
this.currentLibrary = library;
this.log(`Beginning to process library: ${library.name}`);
this.log(`Beginning to process library: ${library.name}`, 'info');
this.items = await this.plexClient.getLibraryContents(library.id);
await this.loop();
}

15
server/job/schedule.ts Normal file
View File

@@ -0,0 +1,15 @@
import schedule from 'node-schedule';
import jobPlexSync from './plexsync';
import logger from '../logger';
export const scheduledJobs: Record<string, schedule.Job> = {};
export const startJobs = (): void => {
// Run full plex sync every 6 hours
scheduledJobs.plexFullSync = schedule.scheduleJob('* */6 * * *', () => {
logger.info('Starting scheduled job: Plex Full Sync', { label: 'Jobs' });
jobPlexSync.run();
});
logger.info('Scheduled jobs loaded', { label: 'Jobs' });
};