//#region src/do-runner.ts
const REARM_DELAY_MS = 1500;
/**
* Alarm-driven job runner — `nudge()` ensures an alarm is pending; `alarm()` drains
* one unit per tick and self-reschedules while backlog remains (re-arm in `finally`).
*/
var JobRunnerDO = class {
	ctx;
	registry;
	env;
	dispatchOpts;
	constructor(ctx, registry, env, dispatchOpts) {
		this.ctx = ctx;
		this.registry = registry;
		this.env = env;
		this.dispatchOpts = dispatchOpts;
	}
	/** Idempotent wake — sets `setAlarm(now)` only when none is already pending. */
	async nudge() {
		if (await this.ctx.getAlarm() != null) return;
		await this.ctx.setAlarm(Date.now());
	}
	async alarm() {
		try {
			const work = await this.pullNext();
			if (work) await this.registry.dispatch(this.env, work, this.dispatchOpts);
		} finally {
			if (await this.hasBacklog()) await this.ctx.setAlarm(Date.now() + REARM_DELAY_MS);
		}
	}
};
//#endregion
export { JobRunnerDO, REARM_DELAY_MS };
