mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: microservices be gone (#9551)
* feat: microservices be gone and api is a worker now too * chore: remove very old startup scripts, surely nobody is using these anymore, right? right?....
This commit is contained in:
parent
ff52300624
commit
85aca2bb54
12 changed files with 206 additions and 190 deletions
49
server/src/utils/workers.spec.ts
Normal file
49
server/src/utils/workers.spec.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { getWorkers } from 'src/utils/workers';
|
||||
|
||||
describe('getWorkers', () => {
|
||||
beforeEach(() => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = '';
|
||||
process.env.IMMICH_WORKERS_EXCLUDE = '';
|
||||
});
|
||||
|
||||
it('should return default workers', () => {
|
||||
expect(getWorkers()).toEqual(['api', 'microservices']);
|
||||
});
|
||||
|
||||
it('should return included workers', () => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = 'api';
|
||||
expect(getWorkers()).toEqual(['api']);
|
||||
});
|
||||
|
||||
it('should excluded workers from defaults', () => {
|
||||
process.env.IMMICH_WORKERS_EXCLUDE = 'api';
|
||||
expect(getWorkers()).toEqual(['microservices']);
|
||||
});
|
||||
|
||||
it('should exclude workers from include list', () => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = 'api,microservices,randomservice';
|
||||
process.env.IMMICH_WORKERS_EXCLUDE = 'randomservice,microservices';
|
||||
expect(getWorkers()).toEqual(['api']);
|
||||
});
|
||||
|
||||
it('should remove whitespace from included workers before parsing', () => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = 'api, microservices';
|
||||
expect(getWorkers()).toEqual(['api', 'microservices']);
|
||||
});
|
||||
|
||||
it('should remove whitespace from excluded workers before parsing', () => {
|
||||
process.env.IMMICH_WORKERS_EXCLUDE = 'api, microservices';
|
||||
expect(getWorkers()).toEqual([]);
|
||||
});
|
||||
|
||||
it('should remove whitespace from included and excluded workers before parsing', () => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = 'api, microservices, randomservice,randomservice2';
|
||||
process.env.IMMICH_WORKERS_EXCLUDE = 'randomservice,microservices, randomservice2';
|
||||
expect(getWorkers()).toEqual(['api']);
|
||||
});
|
||||
|
||||
it('should throw error for invalid workers', () => {
|
||||
process.env.IMMICH_WORKERS_INCLUDE = 'api,microservices,randomservice';
|
||||
expect(getWorkers).toThrowError('Invalid worker(s) found: api,microservices,randomservice');
|
||||
});
|
||||
});
|
||||
21
server/src/utils/workers.ts
Normal file
21
server/src/utils/workers.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const WORKER_TYPES = new Set(['api', 'microservices']);
|
||||
|
||||
export const getWorkers = () => {
|
||||
let workers = ['api', 'microservices'];
|
||||
const includedWorkers = process.env.IMMICH_WORKERS_INCLUDE?.replaceAll(/\s/g, '');
|
||||
const excludedWorkers = process.env.IMMICH_WORKERS_EXCLUDE?.replaceAll(/\s/g, '');
|
||||
|
||||
if (includedWorkers) {
|
||||
workers = includedWorkers.split(',');
|
||||
}
|
||||
|
||||
if (excludedWorkers) {
|
||||
workers = workers.filter((worker) => !excludedWorkers.split(',').includes(worker));
|
||||
}
|
||||
|
||||
if (workers.some((worker) => !WORKER_TYPES.has(worker))) {
|
||||
throw new Error(`Invalid worker(s) found: ${workers}`);
|
||||
}
|
||||
|
||||
return workers;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue