Skip to content

Open source alternative to Semrush and Ahrefs

Resume scheduled rank checks on the hosted platform (#979)

Ben Senescu03b64eb564a2
diff --git a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
index c3d6bdc1..79b1a44a 100644
--- a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
+++ b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
@@ -33,8 +33,6 @@ 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,
randomScheduleDate,
@@ -152,8 +150,6 @@ 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.
@@ -178,9 +174,7 @@ function RankTrackingConfigModalContent({
targetingMode: existingConfig?.locationName ? "local" : "national",
locationName: existingConfig?.locationName ?? undefined,
devices: existingConfig?.devices ?? "mobile",
- schedule:
- existingConfig?.scheduleInterval ??
- (scheduledChecksPaused ? "manual" : "weekly"),
+ schedule: existingConfig?.scheduleInterval ?? "weekly",
// Shown and edited in the browser's timezone; the server converts it to UTC.
scheduleTime: localScheduleTimeFrom(
existingConfig?.nextCheckAt
@@ -342,7 +336,6 @@ function RankTrackingConfigModalContent({
form.setFieldValue("scheduleTime", time);
setScheduleTimeEdited(true);
}}
- scheduledChecksPaused={scheduledChecksPaused}
/>
<form.AppField name="serpDepth">
diff --git a/src/client/features/rank-tracking/ScheduleField.tsx b/src/client/features/rank-tracking/ScheduleField.tsx
index 10ae1437..c6b26141 100644
--- a/src/client/features/rank-tracking/ScheduleField.tsx
+++ b/src/client/features/rank-tracking/ScheduleField.tsx
@@ -43,8 +43,6 @@ type Props = {
onScheduleTimeChange: (scheduleTime: LocalScheduleTime) => void;
/** AI visibility pauses tracking instead of offering a manual schedule. */
allowManual?: boolean;
- /** Only manual, or the schedule already saved, can be picked. */
- scheduledChecksPaused?: boolean;
};
export function ScheduleField({
@@ -53,19 +51,11 @@ export function ScheduleField({
scheduleTime,
onScheduleTimeChange,
allowManual = true,
- scheduledChecksPaused = false,
}: Props) {
const id = useId();
- // Paused: offer manual plus whatever the config already uses, so an edit
- // never silently drops a saved schedule.
- const [pausedSchedule] = useState(schedule);
- const items = scheduledChecksPaused
- ? SCHEDULE_ITEMS.filter(
- (item) => item.value === "manual" || item.value === pausedSchedule,
- )
- : allowManual
- ? SCHEDULE_ITEMS
- : SCHEDULE_ITEMS.filter((item) => item.value !== "manual");
+ const items = allowManual
+ ? SCHEDULE_ITEMS
+ : SCHEDULE_ITEMS.filter((item) => item.value !== "manual");
const [showScheduleTime, setShowScheduleTime] = useState(false);
return (
diff --git a/src/server.ts b/src/server.ts
index 0e1344bf..c85fc8bc 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -7,7 +7,6 @@ import { resolveUserContextFromHeaders } from "@/middleware/ensure-user/resolve"
import { ProjectRepository } from "@/server/features/projects/repositories/ProjectRepository";
import { SamSessionRepository } from "@/server/features/sam/SamSessionRepository";
import { runScheduledRankChecks } from "@/server/features/rank-tracking/services/scheduledRankChecks";
-import { SCHEDULED_RANK_CHECKS_PAUSED } from "@/shared/rank-tracking-pause";
import { reconcileStaleAudits } from "@/server/features/audit/services/auditReconciler";
import { sendFirstAuditEmails } from "@/server/features/audit/services/firstAuditEmails";
import { getOrCreateOrganizationCustomer } from "@/server/billing/subscription";
@@ -253,9 +252,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 && isHostedAuthMode(env.AUTH_MODE)
- ? Promise.resolve()
- : withPgClient(() => runScheduledRankChecks(env)),
+ withPgClient(() => runScheduledRankChecks(env)),
withPgClient(async () => {
const { runScheduledAiVisibility } =
await import("@/server/features/ai-visibility/services/scheduledAiVisibility");
diff --git a/src/server/features/rank-tracking/services/RankTrackingService.management.test.ts b/src/server/features/rank-tracking/services/RankTrackingService.management.test.ts
index b1dbc554..a6f7b929 100644
--- a/src/server/features/rank-tracking/services/RankTrackingService.management.test.ts
+++ b/src/server/features/rank-tracking/services/RankTrackingService.management.test.ts
@@ -14,10 +14,6 @@ const mocks = vi.hoisted(() => ({
fetchKeywordMetricsForList: vi.fn(),
}));
-// These tests cover normal scheduling, not the temporary pause.
-vi.mock("@/shared/rank-tracking-pause", () => ({
- SCHEDULED_RANK_CHECKS_PAUSED: false,
-}));
vi.mock("cloudflare:workers", () => ({ env: { RANK_CHECK_WORKFLOW: {} } }));
vi.mock(
"@/server/features/rank-tracking/repositories/RankTrackingRepository",
diff --git a/src/server/features/rank-tracking/services/RankTrackingService.test.ts b/src/server/features/rank-tracking/services/RankTrackingService.test.ts
index b8bf403c..66a7f302 100644
--- a/src/server/features/rank-tracking/services/RankTrackingService.test.ts
+++ b/src/server/features/rank-tracking/services/RankTrackingService.test.ts
@@ -16,10 +16,6 @@ const mocks = vi.hoisted(() => ({
customerHasPaidPlan: vi.fn(),
}));
-// These tests cover normal scheduling, not the temporary pause.
-vi.mock("@/shared/rank-tracking-pause", () => ({
- SCHEDULED_RANK_CHECKS_PAUSED: false,
-}));
vi.mock("cloudflare:workers", () => ({
env: { RANK_CHECK_WORKFLOW: { create: mocks.startWorkflow } },
}));
diff --git a/src/server/features/rank-tracking/services/RankTrackingService.ts b/src/server/features/rank-tracking/services/RankTrackingService.ts
index b8c87605..a9780c10 100644
--- a/src/server/features/rank-tracking/services/RankTrackingService.ts
+++ b/src/server/features/rank-tracking/services/RankTrackingService.ts
@@ -58,10 +58,7 @@ async function createConfig(input: {
input.projectMarket,
);
const scheduleInterval = input.scheduleInterval ?? "weekly";
- const nextCheckAt = await resolveNextCheckAt(
- scheduleInterval,
- input.scheduleTime,
- );
+ const nextCheckAt = resolveNextCheckAt(scheduleInterval, input.scheduleTime);
const locationName = input.locationName ?? null;
// Before the duplicate/limit checks so an unusable location name is the
@@ -208,10 +205,7 @@ async function updateConfig(
(scheduleInterval !== "manual" && !existing.nextCheckAt)
) {
updates.scheduleInterval = scheduleInterval;
- updates.nextCheckAt = await resolveNextCheckAt(
- scheduleInterval,
- scheduleTime,
- );
+ updates.nextCheckAt = 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 d16a5fe7..981b7464 100644
--- a/src/server/features/rank-tracking/services/configSchedule.ts
+++ b/src/server/features/rank-tracking/services/configSchedule.ts
@@ -1,6 +1,4 @@
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,
isScheduledRankTrackingInterval,
@@ -10,19 +8,11 @@ import type {
RankTrackingConfig,
} from "@/types/schemas/rank-tracking";
-export async function resolveNextCheckAt(
+export function resolveNextCheckAt(
scheduleInterval: RankTrackingConfig["scheduleInterval"],
scheduleTime: RankCheckScheduleTime | undefined,
-): Promise<string | null> {
+): 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 && (await isHostedServerAuthMode())) {
- throw new AppError(
- "VALIDATION_ERROR",
- "Scheduled rank checks are temporarily paused. Use a manual schedule and run checks on demand.",
- );
- }
// Without one the check would quietly repeat on whatever day today is.
if (
scheduleInterval === "weekly" &&
diff --git a/src/shared/rank-tracking-pause.ts b/src/shared/rank-tracking-pause.ts
deleted file mode 100644
index f6726a9b..00000000
--- a/src/shared/rank-tracking-pause.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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;