refactor(server): worker env (#13160)

This commit is contained in:
Jason Rasmussen
2024-10-03 15:28:36 -04:00
committed by GitHub
parent 892a35acb5
commit db1623f43f
10 changed files with 63 additions and 58 deletions

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env node
import { ImmichWorker } from 'src/enum';
import { ConfigRepository } from 'src/repositories/config.repository';
const main = async () => {
const { workers, port } = new ConfigRepository().getEnv();
if (!workers.includes(ImmichWorker.API)) {
process.exit();
}
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 2000);
try {
const response = await fetch(`http://localhost:${port}/api/server-info/ping`, {
signal: controller.signal,
});
if (response.ok) {
const body = await response.json();
if (body.res === 'pong') {
process.exit();
}
}
} catch (error) {
if (error instanceof DOMException === false) {
console.error(error);
}
} finally {
clearTimeout(timeout);
}
process.exit(1);
};
void main();