fffleet-orchestrator 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 CHANGED
@@ -36,4 +36,6 @@ Extra routes: `GET /v1/pools` lists the autoscaling pools. `GET /v1/workers` lis
36
36
 
37
37
  Keep the file on a volume that survives the container. Use one orchestrator per state file.
38
38
 
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
+
39
41
  License: EUPL-1.2
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
3
3
  import { SCOPES, generateSecret, hashSecret } from 'fffleet';
4
4
  import { loadConfig } from '../src/config.js';
5
5
  import { createOrchestrator } from '../src/orchestrator.js';
@@ -79,7 +79,10 @@ async function addClient(args) {
79
79
  data.clients = (data.clients ?? []).filter(c => c.id !== id);
80
80
  const secret = generateSecret();
81
81
  data.clients.push({ id, secretHash: await hashSecret(secret), scopes });
82
- writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
82
+ // Written beside the file and renamed, so a running orchestrator never reads half a file.
83
+ const tmp = `${file}.${process.pid}.tmp`;
84
+ writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
85
+ renameSync(tmp, file);
83
86
  console.log(`client ${id} (${scopes.join(', ')}) written to ${file}`);
84
87
  console.log(`client secret (shown once): ${secret}`);
85
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fffleet-orchestrator",
3
- "version": "2.2.0",
3
+ "version": "2.3.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.2.0"
24
+ "fffleet": "^2.3.1"
25
25
  },
26
26
  "keywords": [
27
27
  "ffmpeg",
@@ -278,6 +278,7 @@ export function createOrchestrator({
278
278
  }
279
279
  if (job.final) return release(job); // cancelled while dispatching; the cancel already reached the worker or will be ignored
280
280
  if (res.status >= 500) {
281
+ await res.body?.cancel().catch(() => {});
281
282
  log(`worker ${worker.id} answered ${res.status} for ${job.id}; trying elsewhere`);
282
283
  worker.cooldownUntil = Date.now() + dispatchCooldownMs;
283
284
  m.dispatchFailures.inc({ worker: worker.id, reason: 'server_error' });
@@ -289,6 +290,7 @@ export function createOrchestrator({
289
290
  job.push({ state: 'failed', error: { code: 'DISPATCH_REJECTED', message: `worker ${worker.id} rejected the job: ${body?.error?.message ?? `HTTP ${res.status}`}` } });
290
291
  return release(job);
291
292
  }
293
+ await res.body?.cancel().catch(() => {}); // the events stream tells us the rest
292
294
  follow(job, worker);
293
295
  }
294
296
 
@@ -357,6 +359,12 @@ export function createOrchestrator({
357
359
  if (!body || typeof body.id !== 'string' || !body.id || typeof body.url !== 'string') {
358
360
  throw new FleetError('INVALID_WORKER', 'register needs id and url', { status: 400 });
359
361
  }
362
+ // The orchestrator calls this address and Prometheus scrapes it, so it has to be a plain http(s) URL.
363
+ try {
364
+ if (!['http:', 'https:'].includes(new URL(body.url).protocol)) throw new Error('not http(s)');
365
+ } catch {
366
+ throw new FleetError('INVALID_WORKER', 'url must be an http or https URL the orchestrator can reach', { status: 400 });
367
+ }
360
368
  let slots;
361
369
  try {
362
370
  slots = normalizeSlots(body.slots ?? { default: 1 });
@@ -622,6 +630,7 @@ export function createOrchestrator({
622
630
  if (jobStore) restore();
623
631
  ({ server, url } = await listen(createApiHandler({ backend, authenticate, metrics: () => registry.render(), extraRoutes }), { port, host }));
624
632
  if (!token && !clientStore) log('no FFFLEET_TOKEN and no clients file: the job API is open to anyone who can reach it');
633
+ if ((token || clientStore) && !workerToken && !scaling) log('no FFFLEET_WORKER_TOKEN: anyone who can reach this orchestrator can register a worker and receive jobs (docs/security.md)');
625
634
  sweeper = setInterval(sweep, sweepMs);
626
635
  sweeper.unref?.();
627
636
  log(`fffleet-orchestrator listening on ${url}`);