TaskGenerator

The TaskGenerator creates and manages gscRefreshTask documents in Sanity based on decay signals.

Constructor

import { TaskGenerator } from '@pagebridge/core'

const generator = new TaskGenerator(sanityClient)

// Or with options
const generator = new TaskGenerator({
  sanity: sanityClient,
  db: drizzleDb  // Optional: for fetching top queries
})
typescript

createTasks(siteId, signals, matches, siteUrl?)

Creates refresh task documents in Sanity for each decay signal. Includes deduplication — skips creating tasks if an open or in-progress task already exists for the same page and reason.

const created = await generator.createTasks(
  siteId,      // Sanity ID of the gscSite document
  signals,     // DecaySignal[] from DecayDetector
  matches,     // MatchResult[] from URLMatcher
  'sc-domain:example.com'
)

console.log(`Created ${created} refresh tasks`)
typescript

What each task contains

  • site — reference to the gscSite document
  • linkedDocument — reference to the matched Sanity content document
  • reasonposition_decay, low_ctr, or impressions_drop
  • severitylow, medium, or high
  • statusopen (default)
  • metrics — position before/now, CTR before/now, impressions
  • queryContext — top 5 queries with impressions, clicks, and position

updateTaskStatus(taskId, status, options?)

Updates the status of an existing task. Handles snooze dates and resolution timestamps.

// Mark as done
await generator.updateTaskStatus(taskId, 'done')

// Snooze for 7 days
await generator.updateTaskStatus(taskId, 'snoozed', {
  snoozeDays: 7,
  notes: 'Will revisit after the product launch'
})

// Dismiss
await generator.updateTaskStatus(taskId, 'dismissed', {
  notes: 'Page is being deprecated'
})
typescript

Available statuses

StatusDescription
openNeeds attention
in_progressBeing worked on
snoozedPostponed until a date
doneCompleted
dismissedIntentionally skipped

See also