diff --git a/prisma/migrations/20250706145720_mark_jobs_as_complete/migration.sql b/prisma/migrations/20250706145720_mark_jobs_as_complete/migration.sql new file mode 100644 index 0000000..a965549 --- /dev/null +++ b/prisma/migrations/20250706145720_mark_jobs_as_complete/migration.sql @@ -0,0 +1,19 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Response" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "pleromaNotificationId" TEXT NOT NULL DEFAULT 'null', + "to" TEXT NOT NULL DEFAULT 'null', + "request" TEXT NOT NULL DEFAULT 'null', + "response" TEXT NOT NULL DEFAULT 'null', + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "processedAt" DATETIME, + "isProcessing" BOOLEAN NOT NULL DEFAULT true, + "isComplete" BOOLEAN NOT NULL DEFAULT true +); +INSERT INTO "new_Response" ("createdAt", "id", "isProcessing", "pleromaNotificationId", "processedAt", "request", "response", "to") SELECT "createdAt", "id", "isProcessing", "pleromaNotificationId", "processedAt", "request", "response", "to" FROM "Response"; +DROP TABLE "Response"; +ALTER TABLE "new_Response" RENAME TO "Response"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index db7bbbb..cb06714 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -20,6 +20,7 @@ model Response { createdAt DateTime @default(now()) processedAt DateTime? isProcessing Boolean @default(true) + isComplete Boolean @default(true) } model User { diff --git a/src/prisma.ts b/src/prisma.ts index 3045205..3a97ea5 100644 --- a/src/prisma.ts +++ b/src/prisma.ts @@ -14,6 +14,7 @@ const storePromptData = async ( request: trimInputData(notification.status.content), to: notification.account.fqn, isProcessing: false, + isComplete: true, }, }); } catch (error: any) { diff --git a/src/util.ts b/src/util.ts index b5bcb9b..5b43a13 100644 --- a/src/util.ts +++ b/src/util.ts @@ -17,6 +17,8 @@ const recordPendingResponse = async (notification: Notification) => { await prisma.response.create({ data: { pleromaNotificationId: notification.id, + isProcessing: true, + isComplete: false, }, }); } catch (error: any) { @@ -49,9 +51,9 @@ const alreadyRespondedTo = async ( ): Promise => { try { const duplicate = await prisma.response.findFirst({ - where: { pleromaNotificationId: notification.id, isProcessing: true }, + where: { pleromaNotificationId: notification.id }, }); - if (duplicate) { + if (duplicate?.isProcessing || duplicate?.isComplete) { return true; } return false;