fffleet-orchestrator 2.4.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +2 -2
- package/src/orchestrator.js +4 -0
- package/src/ui.js +46 -0
package/README.md
CHANGED
|
@@ -39,3 +39,7 @@ Keep the file on a volume that survives the container. Use one orchestrator per
|
|
|
39
39
|
See also the [install and use guide](https://github.com/jsilvanus/fffleet/blob/main/docs/getting-started.md), the [architecture](https://github.com/jsilvanus/fffleet/blob/main/docs/architecture.md) and [security notes](https://github.com/jsilvanus/fffleet/blob/main/docs/security.md).
|
|
40
40
|
|
|
41
41
|
License: EUPL-1.2
|
|
42
|
+
|
|
43
|
+
## Dashboard
|
|
44
|
+
|
|
45
|
+
The orchestrator serves a small dashboard at `/ui/` (set `ui: false` in the library options to turn it off). It has no build step and no data of its own: the page asks you to log in with a client that has the `admin` scope, gets a token from `POST /v1/auth/token`, and then polls `GET /v1/workers` and `GET /v1/jobs` once a second. It shows the number of nodes (distinct worker hosts), workers, slots in use, running and queued jobs, the worker kinds (batch, stream) and pools, and the running jobs. The token is kept in `sessionStorage` only, so it ends with the tab.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fffleet-orchestrator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "fffleet orchestrator: schedules ffmpeg jobs across a pool of fffleet workers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/orchestrator.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "node --test test/*.test.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"fffleet": "^2.
|
|
24
|
+
"fffleet": "^2.5.1"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"ffmpeg",
|
package/src/orchestrator.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { createAutoscaler } from './autoscaler.js';
|
|
3
3
|
import { createProviders } from './providers/index.js';
|
|
4
4
|
import { openSqliteJobStore } from './job-store.js';
|
|
5
|
+
import { serveUi } from './ui.js';
|
|
5
6
|
import { randomUUID } from 'node:crypto';
|
|
6
7
|
import { FleetError, JobRecord, byPriority, canonicalJson, followJobEvents, implicitRequirements, normalizeKinds, normalizeSlots, parseSpec, pruneFinished, satisfies } from 'fffleet';
|
|
7
8
|
import {
|
|
@@ -43,6 +44,7 @@ const REDISPATCH_DELAY_MS = 500;
|
|
|
43
44
|
* @param {{ save(job: JobRecord): void, loadAll(): object[], prune(keep: number): void, close(): void } | null} [opts.store] A job store of your own, instead of `stateFile`.
|
|
44
45
|
* @param {number} [opts.adoptGraceMs] After a restart, how long a running job waits for its worker to report it.
|
|
45
46
|
* @param {number} [opts.dispatchCooldownMs] How long a worker that answered a dispatch with 5xx gets no new jobs.
|
|
47
|
+
* @param {boolean} [opts.ui=true] Serve the dashboard at /ui/ (static files; the data needs a token).
|
|
46
48
|
* @param {(msg: string) => void} [opts.log]
|
|
47
49
|
*/
|
|
48
50
|
export function createOrchestrator({
|
|
@@ -66,6 +68,7 @@ export function createOrchestrator({
|
|
|
66
68
|
stateFile = null,
|
|
67
69
|
store = null,
|
|
68
70
|
adoptGraceMs = 30000,
|
|
71
|
+
ui = true,
|
|
69
72
|
log = () => {},
|
|
70
73
|
} = {}) {
|
|
71
74
|
/** @type {Map<string, Worker>} */
|
|
@@ -542,6 +545,7 @@ export function createOrchestrator({
|
|
|
542
545
|
|
|
543
546
|
async function extraRoutes(req, res, reqUrl, who) {
|
|
544
547
|
const path = reqUrl.pathname;
|
|
548
|
+
if (ui && (await serveUi(req, res, path))) return true;
|
|
545
549
|
if (path === '/v1/auth/token' && req.method === 'POST') {
|
|
546
550
|
const raw = (await readBody(req, 64 * 1024)).toString('utf8');
|
|
547
551
|
const json = (req.headers['content-type'] ?? '').includes('application/json');
|
package/src/ui.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, join, normalize, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/** The static dashboard that ships with the orchestrator (plain HTML, CSS and ESM; no build step). */
|
|
6
|
+
export const UI_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', 'ui');
|
|
7
|
+
|
|
8
|
+
const TYPES = {
|
|
9
|
+
'.html': 'text/html; charset=utf-8',
|
|
10
|
+
'.css': 'text/css; charset=utf-8',
|
|
11
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Serves /ui and /ui/* from UI_DIR. Returns false for any other path.
|
|
16
|
+
* The files hold no data: the page logs in through /v1/auth/token and reads the API with the token it got.
|
|
17
|
+
*/
|
|
18
|
+
export async function serveUi(req, res, pathname) {
|
|
19
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') return false;
|
|
20
|
+
if (pathname === '/ui') {
|
|
21
|
+
res.writeHead(301, { location: '/ui/' });
|
|
22
|
+
res.end();
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (!pathname.startsWith('/ui/')) return false;
|
|
26
|
+
const rel = decodeURIComponent(pathname.slice('/ui/'.length)) || 'index.html';
|
|
27
|
+
const file = normalize(join(UI_DIR, rel));
|
|
28
|
+
const type = TYPES[extname(file)];
|
|
29
|
+
// Refuse anything outside the directory, and anything without a known type.
|
|
30
|
+
if (!file.startsWith(UI_DIR + sep) || !type) return notFound(res);
|
|
31
|
+
let body;
|
|
32
|
+
try {
|
|
33
|
+
body = await readFile(file);
|
|
34
|
+
} catch {
|
|
35
|
+
return notFound(res);
|
|
36
|
+
}
|
|
37
|
+
res.writeHead(200, { 'content-type': type, 'cache-control': 'no-cache', 'x-content-type-options': 'nosniff' });
|
|
38
|
+
res.end(req.method === 'HEAD' ? undefined : body);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function notFound(res) {
|
|
43
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
|
|
44
|
+
res.end('not found');
|
|
45
|
+
return true;
|
|
46
|
+
}
|