Skip to content

Open source alternative to Semrush and Ahrefs

Pause scheduled rank checks only on the hosted platform (#950)

Ben Senescu63acf862f65c
diff --git a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
index 252c58b6..e1de967e 100644
--- a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
+++ b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
@@ -33,6 +33,7 @@ import {
type SaveConfigInput,
} from "./useSaveConfigMutations";
import { ScheduleField } from "./ScheduleField";
+import { isHostedClientAuthMode } from "@/lib/auth-mode";
import { SCHEDULED_RANK_CHECKS_PAUSED } from "@/shared/rank-tracking-pause";
import {
localScheduleTimeFrom,
@@ -151,6 +152,8 @@ function RankTrackingConfigModalContent({
}: Props & { initialMarket: ProjectMarket }) {
const countryId = useId();
const isEdit = !!existingConfig;
+ const scheduledChecksPaused =
+ SCHEDULED_RANK_CHECKS_PAUSED && isHostedClientAuthMode();
const [createdConfigId, setCreatedConfigId] = useState<string>();
// An untouched edit leaves the stored run time alone; anything that changes
// the schedule sends the time on screen so it is the one that gets saved.
@@ -177,7 +180,7 @@ function RankTrackingConfigModalContent({
devices: existingConfig?.devices ?? "mobile",
schedule:
existingConfig?.scheduleInterval ??
- (SCHEDULED_RANK_CHECKS_PAUSED ? "manual" : "weekly"),
+ (scheduledChecksPaused ? "manual" : "weekly"),
// Shown and edited in the browser's timezone; the server converts it to UTC.
scheduleTime: localScheduleTimeFrom(
existingConfig?.nextCheckAt
@@ -339,7 +342,7 @@ function RankTrackingConfigModalContent({
form.setFieldValue("scheduleTime", time);
setScheduleTimeEdited(true);
}}
- scheduledChecksPaused={SCHEDULED_RANK_CHECKS_PAUSED}
+ scheduledChecksPaused={scheduledChecksPaused}
/>
<form.AppField name="serpDepth">
diff --git a/src/client/features/rank-tracking/ScheduledChecksPausedAlert.tsx b/src/client/features/rank-tracking/ScheduledChecksPausedAlert.tsx
index baa7d2be..29b56baa 100644
--- a/src/client/features/rank-tracking/ScheduledChecksPausedAlert.tsx
+++ b/src/client/features/rank-tracking/ScheduledChecksPausedAlert.tsx
@@ -1,9 +1,10 @@
import { AlertTriangle } from "lucide-react";
import { Alert, AlertDescription } from "@/client/components/ui/alert";
+import { isHostedClientAuthMode } from "@/lib/auth-mode";
import { SCHEDULED_RANK_CHECKS_PAUSED } from "@/shared/rank-tracking-pause";
export function ScheduledChecksPausedAlert() {
- if (!SCHEDULED_RANK_CHECKS_PAUSED) return null;
+ if (!SCHEDULED_RANK_CHECKS_PAUSED || !isHostedClientAuthMode()) return null;
return (
<Alert variant="warning">
diff --git a/src/server.ts b/src/server.ts
index 7b3b2c73..2fa91f4e 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -241,7 +241,7 @@ export default {
}
// Scope a per-request Postgres client for the cron run (no-op in D1 mode).
const checks = await Promise.allSettled([
- SCHEDULED_RANK_CHECKS_PAUSED
+ SCHEDULED_RANK_CHECKS_PAUSED && isHostedAuthMode(env.AUTH_MODE)
? Promise.resolve()
: withPgClient(() => runScheduledRankChecks(env)),
withPgClient(async () => {
diff --git a/src/server/features/rank-tracking/services/RankTrackingService.ts b/src/server/features/rank-tracking/services/RankTrackingService.ts
index 24f8b1ad..bb3afe43 100644
--- a/src/server/features/rank-tracking/services/RankTrackingService.ts
+++ b/src/server/features/rank-tracking/services/RankTrackingService.ts
@@ -58,7 +58,10 @@ async function createConfig(input: {
input.projectMarket,
);
const scheduleInterval = input.scheduleInterval ?? "weekly";
- const nextCheckAt = resolveNextCheckAt(scheduleInterval, input.scheduleTime);
+ const nextCheckAt = await resolveNextCheckAt(
+ scheduleInterval,
+ input.scheduleTime,
+ );
const locationName = input.locationName ?? null;
// Before the duplicate/limit checks so an unusable location name is the
@@ -206,7 +209,10 @@ async function updateConfig(
(scheduleInterval !== "manual" && !existing.nextCheckAt)
) {
updates.scheduleInterval = scheduleInterval;
- updates.nextCheckAt = resolveNextCheckAt(scheduleInterval, scheduleTime);
+ updates.nextCheckAt = await resolveNextCheckAt(
+ scheduleInterval,
+ scheduleTime,
+ );
}
await RankTrackingRepository.updateConfig(configId, projectId, updates);
diff --git a/src/server/features/rank-tracking/services/configSchedule.ts b/src/server/features/rank-tracking/services/configSchedule.ts
index d7da5dfa..d16a5fe7 100644
--- a/src/server/features/rank-tracking/services/configSchedule.ts
+++ b/src/server/features/rank-tracking/services/configSchedule.ts
@@ -1,4 +1,5 @@
import { AppError } from "@/server/lib/errors";
+import { isHostedServerAuthMode } from "@/server/lib/runtime-env";
import { SCHEDULED_RANK_CHECKS_PAUSED } from "@/shared/rank-tracking-pause";
import {
computeNextCheckAt,
@@ -9,14 +10,14 @@ import type {
RankTrackingConfig,
} from "@/types/schemas/rank-tracking";
-export function resolveNextCheckAt(
+export async function resolveNextCheckAt(
scheduleInterval: RankTrackingConfig["scheduleInterval"],
scheduleTime: RankCheckScheduleTime | undefined,
-): string | null {
+): Promise<string | null> {
if (isScheduledRankTrackingInterval(scheduleInterval)) {
// Reached only when a schedule is created or changed, so configs keep the
// schedule they already have (and resume when the pause lifts).
- if (SCHEDULED_RANK_CHECKS_PAUSED) {
+ if (SCHEDULED_RANK_CHECKS_PAUSED && (await isHostedServerAuthMode())) {
throw new AppError(
"VALIDATION_ERROR",
"Scheduled rank checks are temporarily paused. Use a manual schedule and run checks on demand.",
diff --git a/src/shared/rank-tracking-pause.ts b/src/shared/rank-tracking-pause.ts
index e3e954ec..f6726a9b 100644
--- a/src/shared/rank-tracking-pause.ts
+++ b/src/shared/rank-tracking-pause.ts
@@ -1,6 +1,8 @@
-// Temporary kill switch for scheduled rank checks while they are unreliable.
-// While true the cron starts no scheduled runs and no config can switch onto a
-// schedule. Existing configs keep their stored schedule, so flipping this back
-// resumes them (overdue ones drain through the scheduler's per-tick budget).
-// Manual checks are unaffected.
+// Temporary kill switch for scheduled rank checks on the hosted platform while
+// they are unreliable. Self-hosted installs keep running their schedules, so
+// every use pairs this with a hosted-mode check. While true the hosted cron
+// starts no scheduled runs and no hosted config can switch onto a schedule.
+// Existing configs keep their stored schedule, so flipping this back resumes
+// them (overdue ones drain through the scheduler's per-tick budget). Manual
+// checks are unaffected.
export const SCHEDULED_RANK_CHECKS_PAUSED = true;