quality / changes (push) Successful in 9s
quality / commitlint (push) Skipped
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 5s
quality / web (push) Successful in 55s
quality / api (push) Successful in 45s
CD / quality (push) Successful in 1m57s
CD / publish (push) Successful in 1m36s
Веса задают долю слотов на общем FQDN (1 к 3 = ¼ и ¾ цикла), TTL 60. В селекте режима показывать текстовое имя, не ID. Co-authored-by: Cursor <[email protected]>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { FastifyInstance } from "fastify";
|
|
import { AsyncTask, SimpleIntervalJob } from "toad-scheduler";
|
|
import * as serviceConfigService from "./service-config-service.js";
|
|
import { WEIGHTED_SLOT_MS } from "./routing/weighted.js";
|
|
|
|
export const WEIGHTED_DNS_JOB_ID = "weighted-dns";
|
|
|
|
export function createWeightedDnsTask(app: FastifyInstance): AsyncTask {
|
|
return new AsyncTask(
|
|
WEIGHTED_DNS_JOB_ID,
|
|
async () => {
|
|
const n = await serviceConfigService.reconcileWeightedDns(app.db, app.cf);
|
|
if (n > 0) {
|
|
app.log.info({ reconciled: n }, "weighted dns rotated");
|
|
}
|
|
},
|
|
(err) => {
|
|
app.log.warn({ err }, "weighted dns rotate failed");
|
|
},
|
|
);
|
|
}
|
|
|
|
export function scheduleWeightedDnsJob(
|
|
app: FastifyInstance,
|
|
task: AsyncTask,
|
|
): void {
|
|
const scheduler = app.scheduler;
|
|
if (!scheduler) return;
|
|
if (scheduler.existsById(WEIGHTED_DNS_JOB_ID)) {
|
|
scheduler.removeById(WEIGHTED_DNS_JOB_ID);
|
|
}
|
|
scheduler.addSimpleIntervalJob(
|
|
new SimpleIntervalJob(
|
|
{ seconds: WEIGHTED_SLOT_MS / 1000, runImmediately: true },
|
|
task,
|
|
{ id: WEIGHTED_DNS_JOB_ID, preventOverrun: true },
|
|
),
|
|
);
|
|
}
|