Convert AI tagging to background job with progress tracking

- Add TaggingJob model for tracking tagging progress
- Convert batch tagging to background job processing (prevents timeouts)
- Add real-time progress polling in UI with percentage/count display
- Add admin notifications when tagging job completes or fails
- Export getTaggingSettings and getAvailableTags functions

After deployment, run: npx prisma migrate deploy

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 11:48:57 +01:00
parent 0b86dc6477
commit 1b2311b4a3
5 changed files with 481 additions and 94 deletions

View File

@@ -324,6 +324,7 @@ model Program {
learningResources LearningResource[]
partners Partner[]
specialAwards SpecialAward[]
taggingJobs TaggingJob[]
@@unique([name, year])
@@index([status])
@@ -375,6 +376,7 @@ model Round {
filteringResults FilteringResult[]
filteringJobs FilteringJob[]
assignmentJobs AssignmentJob[]
taggingJobs TaggingJob[]
@@index([programId])
@@index([status])
@@ -1125,6 +1127,41 @@ enum AssignmentJobStatus {
FAILED
}
// Tracks progress of long-running AI tagging jobs
model TaggingJob {
id String @id @default(cuid())
programId String? // If tagging entire program
roundId String? // If tagging single round
status TaggingJobStatus @default(PENDING)
totalProjects Int @default(0)
processedCount Int @default(0)
taggedCount Int @default(0)
skippedCount Int @default(0)
failedCount Int @default(0)
errorMessage String? @db.Text
errorsJson Json? @db.JsonB // Array of error messages
startedAt DateTime?
completedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations (optional - can tag by program or round)
program Program? @relation(fields: [programId], references: [id], onDelete: Cascade)
round Round? @relation(fields: [roundId], references: [id], onDelete: Cascade)
@@index([programId])
@@index([roundId])
@@index([status])
}
enum TaggingJobStatus {
PENDING
RUNNING
COMPLETED
FAILED
}
// =============================================================================
// SPECIAL AWARDS SYSTEM
// =============================================================================