Skip to content

Commit

Permalink
Refactoring Job config and exposing it to messenger #753
Browse files Browse the repository at this point in the history
  • Loading branch information
bpatrik committed Nov 18, 2023
1 parent 9f52576 commit 7208a3b
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 28 deletions.
11 changes: 6 additions & 5 deletions src/backend/model/jobs/jobs/AlbumCoverFillingJob.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

export class AlbumCoverFillingJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Album Cover Filling']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
public readonly ConfigTemplate: DynamicConfig[] = null;
directoryToSetCover: { id: number; name: string; path: string }[] = null;
status: 'Persons' | 'Albums' | 'Directory' = 'Persons';

Expand All @@ -20,7 +21,7 @@ export class AlbumCoverFillingJob extends Job {
if (!this.directoryToSetCover) {
this.Progress.log('Loading Directories to process');
this.directoryToSetCover =
await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers();
await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers();
this.Progress.Left = this.directoryToSetCover.length + 2;
return true;
}
Expand Down Expand Up @@ -57,7 +58,7 @@ export class AlbumCoverFillingJob extends Job {
private async stepDirectoryCover(): Promise<boolean> {
if (this.directoryToSetCover.length === 0) {
this.directoryToSetCover =
await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers();
await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers();
// double check if there is really no more
if (this.directoryToSetCover.length > 0) {
return true; // continue
Expand All @@ -70,7 +71,7 @@ export class AlbumCoverFillingJob extends Job {
this.Progress.Left = this.directoryToSetCover.length;

await ObjectManagers.getInstance().CoverManager.setAndGetCoverForDirectory(
directory
directory
);
this.Progress.Processed++;
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/AlbumCoverResetJob.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

export class AlbumCoverRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Album Cover Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
public readonly ConfigTemplate: DynamicConfig[] = null;
protected readonly IsInstant = true;

public get Supported(): boolean {
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/AlbumResetJob.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

export class AlbumRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Album Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
public readonly ConfigTemplate: DynamicConfig[] = null;
protected readonly IsInstant = true;

public get Supported(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/model/jobs/jobs/FileJob.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {ConfigTemplateEntry} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
import * as path from 'path';
import {Logger} from '../../../Logger';
Expand All @@ -13,14 +12,15 @@ import {ProjectPath} from '../../../ProjectPath';
import {FileEntity} from '../../database/enitites/FileEntity';
import {DirectoryBaseDTO, DirectoryDTOUtils} from '../../../../common/entities/DirectoryDTO';
import {DirectoryScanSettings, DiskManager} from '../../fileaccess/DiskManager';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

const LOG_TAG = '[FileJob]';

/**
* Abstract class for thumbnail creation, file deleting etc.
*/
export abstract class FileJob<S extends { indexedOnly?: boolean } = { indexedOnly?: boolean }> extends Job<S> {
public readonly ConfigTemplate: ConfigTemplateEntry[] = [];
public readonly ConfigTemplate: DynamicConfig[] = [];
directoryQueue: string[] = [];
fileQueue: string[] = [];
DBProcessing = {
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/GalleryResetJob.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

export class GalleryRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Gallery Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
public readonly ConfigTemplate: DynamicConfig[] = null;
protected readonly IsInstant = true;

public get Supported(): boolean {
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/IndexingJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {ObjectManagers} from '../../ObjectManagers';
import * as path from 'path';
import * as fs from 'fs';
import {Job} from './Job';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {JobProgressStates} from '../../../../common/entities/job/JobProgressDTO';
import {ProjectPath} from '../../../ProjectPath';
import {backendTexts} from '../../../../common/BackendTexts';
import {ParentDirectoryDTO} from '../../../../common/entities/DirectoryDTO';
import {Logger} from '../../../Logger';
import {FileDTO} from '../../../../common/entities/FileDTO';
import {DiskManager} from '../../fileaccess/DiskManager';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

const LOG_TAG = '[IndexingJob]';

Expand All @@ -18,7 +19,7 @@ export class IndexingJob<
> extends Job<S> {
public readonly Name = DefaultsJobs[DefaultsJobs.Indexing];
directoriesToIndex: string[] = [];
public readonly ConfigTemplate: ConfigTemplateEntry[] = [
public readonly ConfigTemplate: DynamicConfig[] = [
{
id: 'indexChangesOnly',
type: 'boolean',
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/Job.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Logger} from '../../../Logger';
import {IJob} from './IJob';
import {ConfigTemplateEntry, JobDTO, JobDTOUtils,} from '../../../../common/entities/job/JobDTO';
import {JobDTO, JobDTOUtils} from '../../../../common/entities/job/JobDTO';
import {JobProgress} from './JobProgress';
import {IJobListener} from './IJobListener';
import {JobProgressStates} from '../../../../common/entities/job/JobProgressDTO';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';

declare const process: { nextTick: (_: unknown) => void };
declare const global: { gc: () => void };
Expand All @@ -27,7 +28,7 @@ export abstract class Job<T extends Record<string, unknown> = Record<string, unk

public abstract get Name(): string;

public abstract get ConfigTemplate(): ConfigTemplateEntry[];
public abstract get ConfigTemplate(): DynamicConfig[];

public get Progress(): JobProgress {
return this.progress;
Expand Down
5 changes: 3 additions & 2 deletions src/backend/model/jobs/jobs/TempFolderCleaningJob.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import * as path from 'path';
import * as fs from 'fs';
import {Job} from './Job';
import {ProjectPath} from '../../../ProjectPath';
import {GPXProcessing} from '../../fileaccess/fileprocessing/GPXProcessing';
import {PhotoProcessing} from '../../fileaccess/fileprocessing/PhotoProcessing';
import {VideoProcessing} from '../../fileaccess/fileprocessing/VideoProcessing';
import { DynamicConfig } from '../../../../common/entities/DynamicConfig';

export class TempFolderCleaningJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Temp Folder Cleaning']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
public readonly ConfigTemplate: DynamicConfig[] = null;
public readonly Supported: boolean = true;
directoryQueue: string[] = [];
private tempRootCleaned = false;
Expand Down
3 changes: 2 additions & 1 deletion src/backend/model/jobs/jobs/TopPickSendJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {PhotoEntity} from '../../database/enitites/PhotoEntity';
import {EmailMediaMessenger} from '../../mediamessengers/EmailMediaMessenger';
import {MediaPickDTO} from '../../../../common/entities/MediaPickDTO';
import {MediaDTOUtils} from '../../../../common/entities/MediaDTO';
import {DynamicConfig} from '../../../../common/entities/DynamicConfig';


export class TopPickSendJob extends Job<{
Expand All @@ -19,7 +20,7 @@ export class TopPickSendJob extends Job<{
}> {
public readonly Name = DefaultsJobs[DefaultsJobs['Top Pick Sending']];
public readonly Supported: boolean = true;
public readonly ConfigTemplate: ConfigTemplateEntry[] = [
public readonly ConfigTemplate: DynamicConfig[] = [
{
id: 'mediaPick',
type: 'MediaPickDTO-array',
Expand Down
17 changes: 17 additions & 0 deletions src/common/entities/DynamicConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {backendText} from '../BackendTexts';
import {fieldType} from './job/JobDTO';

/**
* Dynamic configs are not part of the typeconfig maintained config.
* Pigallery uses them to dynamically define configuration
* on the serverside so the client can parse and render it.
* It is mostly used for configuring jobs
*/
export interface DynamicConfig {
id: string;
// Use a predefined and localized backend text id or explicitly define the text
name: backendText | string;
description: backendText | string;
type: fieldType;
defaultValue: unknown;
}
10 changes: 2 additions & 8 deletions src/common/entities/job/JobDTO.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {backendText} from '../../BackendTexts';
import {DynamicConfig} from '../DynamicConfig';

export type fieldType = 'string' | 'string-array' | 'number' | 'boolean' | 'number-array' | 'MediaPickDTO-array';

Expand All @@ -17,17 +18,10 @@ export enum DefaultsJobs {
'Top Pick Sending' = 12
}

export interface ConfigTemplateEntry {
id: string;
name: backendText;
description: backendText;
type: fieldType;
defaultValue: any;
}

export interface JobDTO {
Name: string;
ConfigTemplate: ConfigTemplateEntry[];
ConfigTemplate: DynamicConfig[];
}

export const JobDTOUtils = {
Expand Down

0 comments on commit 7208a3b

Please sign in to comment.