Files
splatoon3.ink/workers/updater/test/fakeCompressor.mjs
Matt Isenhower a406f73622 Add switches for renewals and compression; judge renewals by their result
A credential renewal now counts as failed only when it ends without a new
bullet token. A step that failed and was made up for by a later one (znca
briefly unavailable, say) is kept as a warning and no longer goes to
Sentry.

Everything that runs on its own now has a switch in the admin panel:
scheduled renewals (one switch for every region) and the daily archive
compression join the lanes' scheduling switches. The compressor's starts
from AUTOMATIC_SCHEDULING_ENABLED: on in dev, off in production, so the
production compressor can be deployed before spectre stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:08:10 -08:00

58 lines
2.0 KiB
JavaScript

// Stands in for the archive compressor Worker (workers/compressor/) in the Worker tests: the
// updater's COMPRESSOR binding points at that Worker's Durable Object, which needs a container.
// It keeps the same status(), run(), start() and setScheduling() shapes, and records runs without running anything.
import { DurableObject } from 'cloudflare:workers';
export class Compressor extends DurableObject {
async status() {
let enabled = (await this.ctx.storage.get('scheduled')) ?? true;
return {
now: Date.now(),
enabled,
nextAt: enabled ? Date.UTC(2030, 0, 1, 0, 30) : null,
current: (await this.ctx.storage.get('current')) ?? null,
runs: (await this.ctx.storage.get('runs')) ?? [],
};
}
async setScheduling({ enabled }) {
await this.ctx.storage.put('scheduled', enabled);
return { ok: true, enabled };
}
async run(id) {
let current = await this.ctx.storage.get('current');
let run = current?.id === id ? current : ((await this.ctx.storage.get('runs')) ?? []).find(run => run.id === id);
return run ? { ...run, running: run === current, logs: { lines: [{ at: run.startedAt, level: 'info', text: 'Found 0 dates to archive' }], omitted: 0 } } : null;
}
async start({ trigger, dryRun = false }) {
let current = await this.ctx.storage.get('current');
if (current) {
return { ok: false, busy: true, current };
}
current = { id: crypto.randomUUID(), trigger, maxDays: 10, dryRun, startedAt: Date.now() };
await this.ctx.storage.put('current', current);
return { ok: true, current };
}
// Test helper: end the run in progress as the real compressor would.
async finish(result) {
let current = await this.ctx.storage.get('current');
let runs = (await this.ctx.storage.get('runs')) ?? [];
await this.ctx.storage.put('runs', [{ ...current, ...result, finishedAt: Date.now() }, ...runs]);
await this.ctx.storage.delete('current');
}
}
export default {
fetch: () => new Response('Not found', { status: 404 }),
};