-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Context
PR #122 migrated from NuxtHub Admin + Cloudflare Pages to self-hosted Cloudflare Workers. Following improvements needed:
Tasks
1. Fix notification parameter semantics
- File:
server/tasks/sync/epochs.ts:46 - Issue:
sendNewEpochNotification(missingEpoch, missingEpochs.length)- second param should be "remaining count" not "total before sync" - Fix:
await sendNewEpochNotification(missingEpoch, missingEpochs.length - 1)
2. Add MAX_EPOCHS_PER_RUN to runtime config
- Files:
nuxt.config.ts,server/tasks/sync/epochs.ts:9 - Current:
const MAX_EPOCHS_PER_RUN = import.meta.dev ? Infinity : 50 - Fix: Move to
runtimeConfigwithsafeRuntimeConfigvalidation - Benefit: Configurable per environment via env vars
3. Add structured logging to scheduled tasks
- Files:
server/tasks/sync/epochs.ts,server/tasks/sync/snapshot.ts - Fix: Add
consola.info()at:- Task start with config summary
- Each epoch synced (progress indicator)
- Task end with timing and summary stats
- Example:
consola.info(`[sync:epochs] Starting sync, max epochs: ${MAX_EPOCHS_PER_RUN}`) consola.success(`[sync:epochs] Synced ${totalSynced} epochs in ${elapsed}ms`)
4. Standardize environment detection
- Issue: Mixed use of
import.meta.devandisDevelopmentfromstd-env - Files:
server/tasks/sync/snapshot.ts:16(usesimport.meta.dev✅)server/utils/slack.ts:3(usesisDevelopmentfromstd-env❌)
- Fix: Use
import.meta.devconsistently, removestd-envimport fromslack.ts
5. Sanitize stack traces in Slack notifications
- File:
server/utils/slack.ts - Issue: Full stack traces expose internal paths, dependency versions
- Fix: In production, truncate stack to first 3-5 lines or exclude entirely
- Example:
stack: import.meta.dev ? error?.stack : error?.stack?.split('\n').slice(0, 3).join('\n')
6. Extract error handling helper (DRY)
- Files:
server/tasks/sync/epochs.ts,server/tasks/sync/snapshot.ts - Issue: Repeated pattern in both tasks:
const error = new Error(rangeError || 'Unable to fetch range') await sendSyncFailureNotification('missing-epoch', error) return { result: { success: false, error: rangeError } }
- Fix: Create
server/utils/task-error.ts:Usage:export async function handleTaskError( taskName: string, error: unknown, defaultMsg: string ) { const err = new Error(String(error) || defaultMsg) await sendSyncFailureNotification(taskName, err) return { result: { success: false, error: String(error) } } }
return await handleTaskError('missing-epoch', rangeError, 'Unable to fetch range')
Labels
Add: enhancement, refactor
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels