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:
@@ -0,0 +1,38 @@
|
||||
-- Add TaggingJob table for background AI tagging
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "TaggingJobStatus" AS ENUM ('PENDING', 'RUNNING', 'COMPLETED', 'FAILED');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "TaggingJob" (
|
||||
"id" TEXT NOT NULL,
|
||||
"programId" TEXT,
|
||||
"roundId" TEXT,
|
||||
"status" "TaggingJobStatus" NOT NULL DEFAULT 'PENDING',
|
||||
"totalProjects" INTEGER NOT NULL DEFAULT 0,
|
||||
"processedCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"taggedCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"skippedCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"failedCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"errorMessage" TEXT,
|
||||
"errorsJson" JSONB,
|
||||
"startedAt" TIMESTAMP(3),
|
||||
"completedAt" TIMESTAMP(3),
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "TaggingJob_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "TaggingJob_programId_idx" ON "TaggingJob"("programId");
|
||||
CREATE INDEX IF NOT EXISTS "TaggingJob_roundId_idx" ON "TaggingJob"("roundId");
|
||||
CREATE INDEX IF NOT EXISTS "TaggingJob_status_idx" ON "TaggingJob"("status");
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "TaggingJob" ADD CONSTRAINT "TaggingJob_programId_fkey"
|
||||
FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "TaggingJob" ADD CONSTRAINT "TaggingJob_roundId_fkey"
|
||||
FOREIGN KEY ("roundId") REFERENCES "Round"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
@@ -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
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user