perf(startup): skip inactive background services

This commit is contained in:
hungtrinh
2026-07-16 11:17:46 +07:00
parent 7dfb346667
commit 27b37705b3
8 changed files with 107 additions and 16 deletions

View File

@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
import { getSettings, updateSettings } from "@/lib/localDb";
import { applyOutboundProxyEnv } from "@/lib/network/outboundProxy";
import { resetComboRotation } from "open-sse/services/combo.js";
import { runQuotaAutoPingTick } from "@/shared/services/quotaAutoPing";
import bcrypt from "bcryptjs";
export const dynamic = "force-dynamic";
@@ -101,10 +100,12 @@ export async function PATCH(request) {
Object.prototype.hasOwnProperty.call(body, "claudeAutoPing") ||
Object.prototype.hasOwnProperty.call(body, "codexAutoPing")
) {
// Run once immediately after opt-in changes so users don't wait for the next scheduler tick.
runQuotaAutoPingTick().catch((error) => {
console.warn("[AutoPing] settings-triggered tick failed:", error.message);
});
// Keep the scheduler absent when no account opted in; load its provider graph only on demand.
import("@/shared/services/quotaAutoPing")
.then(({ configureQuotaAutoPing }) => {
configureQuotaAutoPing(settings);
})
.catch((error) => console.warn("[AutoPing] settings update failed:", error.message));
}
const { password, oidcClientSecret, ...safeSettings } = settings;

View File

@@ -1,9 +1,14 @@
import { NextResponse } from "next/server";
import { disableTunnel } from "@/lib/tunnel";
import { getSettings } from "@/lib/localDb";
import { configureTunnelMonitoring } from "@/shared/services/initializeApp";
export async function POST() {
try {
const result = await disableTunnel();
getSettings()
.then(configureTunnelMonitoring)
.catch((error) => console.warn("Tunnel monitor update failed:", error.message));
return NextResponse.json(result);
} catch (error) {
console.error("Tunnel disable error:", error);

View File

@@ -1,11 +1,16 @@
import { NextResponse } from "next/server";
import { enableTunnel } from "@/lib/tunnel";
import { getSettings } from "@/lib/localDb";
import { configureTunnelMonitoring } from "@/shared/services/initializeApp";
const DNS_WARMUP_DELAY_MS = 8000;
export async function POST() {
try {
const result = await enableTunnel();
getSettings()
.then(configureTunnelMonitoring)
.catch((error) => console.warn("Tunnel monitor start failed:", error.message));
// Wait for DNS warmup to propagate at Cloudflare edge after tunnel registered
await new Promise((r) => setTimeout(r, DNS_WARMUP_DELAY_MS));
return NextResponse.json(result);

View File

@@ -1,9 +1,14 @@
import { NextResponse } from "next/server";
import { disableTailscale } from "@/lib/tunnel";
import { getSettings } from "@/lib/localDb";
import { configureTunnelMonitoring } from "@/shared/services/initializeApp";
export async function POST() {
try {
const result = await disableTailscale();
getSettings()
.then(configureTunnelMonitoring)
.catch((error) => console.warn("Tailscale monitor update failed:", error.message));
return NextResponse.json(result);
} catch (error) {
console.error("Tailscale disable error:", error);

View File

@@ -1,9 +1,14 @@
import { NextResponse } from "next/server";
import { enableTailscale } from "@/lib/tunnel";
import { getSettings } from "@/lib/localDb";
import { configureTunnelMonitoring } from "@/shared/services/initializeApp";
export async function POST() {
try {
const result = await enableTailscale();
getSettings()
.then(configureTunnelMonitoring)
.catch((error) => console.warn("Tailscale monitor start failed:", error.message));
return NextResponse.json(result);
} catch (error) {
console.error("Tailscale enable error:", error.message);