Repository navigation
feat(indexnow): re-enable submission for the curated set #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
639e21a
6863a67
01aca6e
fb5935d
91ea1d2
d5bec24
13a2d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| -- IndexNow submission memory. | ||
| -- `indexnow_urls` holds the fingerprint of each URL the last time it was | ||
| -- accepted, so a URL is submitted only when it is new or its fingerprint moved. | ||
| -- `indexnow_batches` is the ledger the daily budget reads. `indexnow_state` is | ||
| -- one row: the backoff clock and, after repeated failures, the halt reason. | ||
| CREATE TABLE indexnow_urls ( | ||
| url TEXT PRIMARY KEY, | ||
| fingerprint TEXT NOT NULL, | ||
| submitted_at INTEGER NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE indexnow_batches ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| submitted_at INTEGER NOT NULL, | ||
| url_count INTEGER NOT NULL CHECK (url_count > 0), | ||
| http_status INTEGER NOT NULL | ||
| ); | ||
|
|
||
| CREATE INDEX idx_indexnow_batches_submitted ON indexnow_batches(submitted_at); | ||
|
|
||
| CREATE TABLE indexnow_state ( | ||
| id INTEGER PRIMARY KEY CHECK (id = 1), | ||
| strikes INTEGER NOT NULL DEFAULT 0, | ||
| not_before INTEGER NOT NULL DEFAULT 0, | ||
| halt_reason TEXT, | ||
| updated_at INTEGER NOT NULL DEFAULT 0 | ||
| ); | ||
|
|
||
| INSERT INTO indexnow_state (id) VALUES (1); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { INDEXNOW_KEY } from '~~/server/utils/indexnow' | ||
|
|
||
| /** | ||
| * Answer the IndexNow key file from the Worker. | ||
| * | ||
| * The task checks this URL through the SELF binding, and Nitro's public asset | ||
| * table is empty here (see `nitro.alias` in nuxt.config.ts). A static file in | ||
| * `public/` may not be reachable that way, so the Worker serves the key itself. | ||
| * The key has one source: `INDEXNOW_KEY`. | ||
| */ | ||
| export default defineEventHandler((event) => { | ||
| setResponseHeader(event, 'content-type', 'text/plain; charset=utf-8') | ||
| setResponseHeader(event, 'cache-control', 'public, max-age=3600') | ||
| return INDEXNOW_KEY | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /// <reference types="@cloudflare/workers-types" /> | ||
|
|
||
| import { resolveCloudflareBindings } from '@harlan-zw/nuxt-cloudflare/bindings' | ||
| import { runIndexNow, runNeedsAttention } from '~~/server/utils/indexnow' | ||
| import { runObservedScheduledTask } from '~~/server/utils/scheduled-run' | ||
| import { reportJobRun } from '~~/server/utils/sync-job-reporter' | ||
| import { observedSchedulePolicy } from '#shared/schedule-policy' | ||
|
|
||
| const CRON = '10 * * * *' | ||
|
|
||
| /** | ||
| * Scheduled task: tell IndexNow about curated URLs that are new or changed. | ||
| * | ||
| * The URL set comes from the same sitemaps Google reads (skills, pages, | ||
| * authors, sources), so a URL we do not advertise is never submitted. The caps | ||
| * and the 429 backoff live in `server/utils/indexnow.ts`. | ||
| */ | ||
| export default defineScheduledTask({ | ||
| name: 'indexnow-submit', | ||
| cron: '10 * * * *', | ||
| description: 'Submit new or changed curated URLs to IndexNow', | ||
| async run({ context }) { | ||
| const env = resolveCloudflareBindings<Cloudflare.Env>(context) | ||
| const db = env?.DB as D1Database | undefined | ||
| const self = env?.SELF as Fetcher | undefined | ||
| if (!env || !db || !self) { | ||
| emitOperationalEvent(createWideEvent({ operation: 'indexnow-submit', outcome: 'binding-missing' })) | ||
| return { result: { error: 'no-db-or-self' } } | ||
| } | ||
|
|
||
| return await runObservedScheduledTask({ | ||
| db, | ||
| env, | ||
| context, | ||
| policy: observedSchedulePolicy('indexnow-submit'), | ||
| }, async () => { | ||
| const startedAt = Date.now() | ||
| const run = await runIndexNow({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. βͺ A thrown run never updates sync_jobs, so /admin/integrity can show a stale ok status for a task that is failing hourly Β· The effect calls runIndexNow without try/catch; if it throws (selfFetch body read, recordAttempt/settle D1 batch failure) reportJobRun at line ~57 never executes, so sync_jobs keeps its stale last_status while sibling task ai-ready-cron.ts reports status 'error' in a catch before rethrowing. runObservedScheduledTask records the failure only in scheduled_runs. Harlan Agent Kit automated review, not Harlan's Β· AI policy |
||
| db, | ||
| selfFetch: url => self.fetch(url), | ||
| send: (input, init) => fetch(input, init), | ||
| now: () => Math.floor(Date.now() / 1000), | ||
| }) | ||
| const attention = runNeedsAttention(run) | ||
| if (attention !== null) { | ||
| // A halt or repeated failure must be readable in logs, not only in D1. | ||
| console.error(`[indexnow-submit] ${run._tag}: ${attention}`) | ||
| emitOperationalEvent(createWideEvent({ | ||
| operation: 'indexnow-submit', | ||
| outcome: run._tag, | ||
| reason: attention, | ||
| })) | ||
| } | ||
| await reportJobRun(db, 'indexnow-submit', { | ||
| cron: CRON, | ||
| status: attention === null ? 'ok' : 'partial', | ||
| durationMs: Date.now() - startedAt, | ||
| error: attention, | ||
| }) | ||
| return { result: run } | ||
| }) | ||
| }, | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.