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
})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`)What each task contains
- site — reference to the gscSite document
- linkedDocument — reference to the matched Sanity content document
- reason —
position_decay,low_ctr, orimpressions_drop - severity —
low,medium, orhigh - status —
open(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'
})Available statuses
| Status | Description |
|---|---|
open | Needs attention |
in_progress | Being worked on |
snoozed | Postponed until a date |
done | Completed |
dismissed | Intentionally skipped |