fffleet-worker 2.2.0 → 2.3.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/bin/fffleet-worker.js +2 -0
- package/package.json +2 -2
- package/src/worker.js +28 -2
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ docker run -p 5100:5100 -e FFFLEET_TOKEN=secret ghcr.io/jsilvanus/fffleet-worker
|
|
|
15
15
|
| `FFFLEET_SLOTS` | `default=2` | Slot pools, e.g. `default=2,stream=1`, or `auto` (from the CPU count) / `auto:4` (4 cores per slot). |
|
|
16
16
|
| `FFFLEET_KINDS` | `batch,stream` | Job kinds this worker takes. Others get 422 `UNSUPPORTED_KIND`, and the orchestrator does not send them. |
|
|
17
17
|
| `FFFLEET_CAPABILITIES` | | Extra capabilities, comma separated, e.g. `mount:/media,site:hel1`. |
|
|
18
|
+
| `FFFLEET_PROBE` | | Hosts to test with a TCP connect, comma separated `[alias=]host:port`, e.g. `mediamtx=10.1.2.3:8554,db.internal:5432`. While one connects the worker advertises `net:<host>:<port>`, plus `net:<alias>` (or `net:<host>` for a host name without alias). A job with `requires: ['net:mediamtx']` then only runs where that host is reachable, and a worker that loses it drops out of scheduling by itself. |
|
|
19
|
+
| `FFFLEET_PROBE_INTERVAL_MS` | `30000` | How often the probes run. |
|
|
18
20
|
| `FFFLEET_ORCHESTRATOR_URL` | | Register and heartbeat here. |
|
|
19
21
|
| `FFFLEET_WORKER_TOKEN` | | Token for the orchestrator. |
|
|
20
22
|
| `FFFLEET_ADVERTISE_URL` | listen URL | URL the orchestrator should call this worker on. |
|
|
@@ -36,4 +38,6 @@ Programmatic use: `import { createWorker } from 'fffleet-worker'`. Pass `executo
|
|
|
36
38
|
|
|
37
39
|
`GET /metrics` (Prometheus text format, `metrics` scope or the static token) reports slots, running jobs with their encoding speed and fps, ffmpeg CPU and memory, bytes staged and uploaded, and host load and memory.
|
|
38
40
|
|
|
41
|
+
See also the [install and use guide](https://github.com/jsilvanus/fffleet/blob/main/docs/getting-started.md) and [security notes](https://github.com/jsilvanus/fffleet/blob/main/docs/security.md).
|
|
42
|
+
|
|
39
43
|
License: EUPL-1.2
|
package/bin/fffleet-worker.js
CHANGED
|
@@ -34,6 +34,8 @@ const worker = createWorker({
|
|
|
34
34
|
keysUrl: env.FFFLEET_KEYS_URL || ((env.FFFLEET_TOKEN || env.FFFLEET_WORKER_TOKEN) && env.FFFLEET_ORCHESTRATOR_URL ? `${env.FFFLEET_ORCHESTRATOR_URL.replace(/\/+$/, '')}/v1/auth/keys` : null),
|
|
35
35
|
workRoot: env.FFFLEET_WORK_DIR || undefined,
|
|
36
36
|
extraCapabilities: list(env.FFFLEET_CAPABILITIES),
|
|
37
|
+
probe: list(env.FFFLEET_PROBE),
|
|
38
|
+
probeIntervalMs: Number(env.FFFLEET_PROBE_INTERVAL_MS ?? 30000),
|
|
37
39
|
orchestratorUrl: env.FFFLEET_ORCHESTRATOR_URL || null,
|
|
38
40
|
orchestratorToken: env.FFFLEET_WORKER_TOKEN || null,
|
|
39
41
|
advertiseUrl: env.FFFLEET_ADVERTISE_URL || null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fffleet-worker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "fffleet worker daemon: runs ffmpeg jobs and serves the fffleet job API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/worker.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "node --test test/*.test.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"fffleet": "^2.
|
|
24
|
+
"fffleet": "^2.3.1"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"ffmpeg",
|
package/src/worker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hostname } from 'node:os';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { JobManager, detectCapabilities } from 'fffleet';
|
|
3
|
+
import { JobManager, detectCapabilities, parseProbes, probeCapabilities } from 'fffleet';
|
|
4
4
|
import {
|
|
5
5
|
Registry, close, createApiHandler, createAuthenticator, createRemoteKeySet, createTokenVerifier,
|
|
6
6
|
hostMetrics, jobMetrics, listen, procStats, processMetrics,
|
|
@@ -24,6 +24,8 @@ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.u
|
|
|
24
24
|
* @param {string} [opts.ffmpegPath]
|
|
25
25
|
* @param {string} [opts.workRoot]
|
|
26
26
|
* @param {string[]} [opts.extraCapabilities] Added to the detected ones, e.g. 'mount:/data/media'.
|
|
27
|
+
* @param {string | string[]} [opts.probe] Hosts to test with a TCP connect, `[alias=]host:port`. While one connects the worker advertises net:<host>:<port> (and net:<alias>).
|
|
28
|
+
* @param {number} [opts.probeIntervalMs]
|
|
27
29
|
* @param {string | null} [opts.orchestratorUrl]
|
|
28
30
|
* @param {string | null} [opts.orchestratorToken] Worker token the orchestrator expects.
|
|
29
31
|
* @param {string | null} [opts.advertiseUrl] URL the orchestrator should call; defaults to the listen URL.
|
|
@@ -44,6 +46,8 @@ export function createWorker({
|
|
|
44
46
|
ffmpegPath = 'ffmpeg',
|
|
45
47
|
workRoot,
|
|
46
48
|
extraCapabilities = [],
|
|
49
|
+
probe = [],
|
|
50
|
+
probeIntervalMs = 30000,
|
|
47
51
|
orchestratorUrl = null,
|
|
48
52
|
orchestratorToken = null,
|
|
49
53
|
advertiseUrl = null,
|
|
@@ -55,7 +59,19 @@ export function createWorker({
|
|
|
55
59
|
log = () => {},
|
|
56
60
|
} = {}) {
|
|
57
61
|
const manager = new JobManager({ slots, kinds, ffmpegPath, workRoot, workerId: id, progressIntervalMs, executors, s3, cache });
|
|
62
|
+
const probes = parseProbes(probe);
|
|
63
|
+
let baseCapabilities = [];
|
|
64
|
+
let probed = [];
|
|
58
65
|
let capabilities = [];
|
|
66
|
+
let probeTimer = null;
|
|
67
|
+
const rebuild = () => { capabilities = [...new Set([...baseCapabilities, ...probed])].sort(); };
|
|
68
|
+
async function refreshProbes() {
|
|
69
|
+
const next = await probeCapabilities(probes);
|
|
70
|
+
const changed = next.join() !== probed.join();
|
|
71
|
+
probed = next;
|
|
72
|
+
rebuild();
|
|
73
|
+
if (changed) log(`reachable: ${next.join(', ') || 'none of the probed hosts'}`);
|
|
74
|
+
}
|
|
59
75
|
let server = null;
|
|
60
76
|
let url = null;
|
|
61
77
|
let heartbeat = null;
|
|
@@ -150,8 +166,17 @@ export function createWorker({
|
|
|
150
166
|
// type:ffmpeg and type:ffprobe come from detection, so a machine without ffmpeg does not claim it.
|
|
151
167
|
const types = Object.keys(manager.executors).filter(t => t !== 'ffmpeg' && t !== 'ffprobe').map(t => `type:${t}`);
|
|
152
168
|
const schemes = manager.s3 ? ['scheme:s3'] : [];
|
|
153
|
-
|
|
169
|
+
baseCapabilities = [...new Set([...(await detectCapabilities(ffmpegPath)), ...types, ...schemes, ...extraCapabilities])];
|
|
170
|
+
await refreshProbes();
|
|
171
|
+
if (probes.length) {
|
|
172
|
+
// The heartbeat carries the capabilities, so a host that becomes (un)reachable is picked up by the orchestrator within a beat.
|
|
173
|
+
probeTimer = setInterval(() => void refreshProbes().catch(() => {}), probeIntervalMs);
|
|
174
|
+
probeTimer.unref?.();
|
|
175
|
+
}
|
|
154
176
|
({ server, url } = await listen(createApiHandler({ backend, authenticate, metrics: () => registry.render() }), { port, host }));
|
|
177
|
+
if (!token && !keysUrl && !['127.0.0.1', '::1', 'localhost'].includes(host)) {
|
|
178
|
+
log('no FFFLEET_TOKEN or FFFLEET_WORKER_TOKEN: anyone who can reach this port can run ffmpeg as this user (docs/security.md)');
|
|
179
|
+
}
|
|
155
180
|
log(`fffleet-worker ${id} listening on ${url} with slots ${JSON.stringify(manager.slots)} for ${manager.kinds.join(' and ')} jobs`);
|
|
156
181
|
if (orchestratorUrl) {
|
|
157
182
|
await register().catch(err => log(`first registration failed, retrying: ${err.message}`));
|
|
@@ -164,6 +189,7 @@ export function createWorker({
|
|
|
164
189
|
/** Stops taking jobs, cancels running ones and closes the server. */
|
|
165
190
|
async stop() {
|
|
166
191
|
clearInterval(heartbeat);
|
|
192
|
+
clearInterval(probeTimer);
|
|
167
193
|
await manager.close();
|
|
168
194
|
if (server) await close(server);
|
|
169
195
|
},
|