Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/return schedule in bot #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:

- Changed the type of `botId` on the `Schedules` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- AlterTable
ALTER TABLE "Schedules" DROP COLUMN "botId",
ADD COLUMN "botId" UUID NOT NULL;

-- AddForeignKey
ALTER TABLE "Schedules" ADD CONSTRAINT "Schedules_botId_fkey" FOREIGN KEY ("botId") REFERENCES "Bot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
8 changes: 5 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ model Bot {
tags String[]
botImage String?
meta Json?
schedules Schedules[]
}

model UserSegment {
Expand Down Expand Up @@ -134,10 +135,11 @@ model ConversationLogic {
}

model Schedules {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
createdAt DateTime @default(now())
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
createdAt DateTime @default(now())
scheduledAt DateTime
authToken String
botId String
bot Bot @relation(fields: [botId], references: [id])
config Json
botId String @db.Uuid
}
4 changes: 4 additions & 0 deletions src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class BotService implements OnModuleInit {
adapter: true,
},
},
schedules: {},
};

pause(id: string) {
Expand Down Expand Up @@ -200,6 +201,7 @@ export class BotService implements OnModuleInit {
this.schedulerRegistry.addCronJob(`notification_${randomUUID()}`, job);
job.start();
this.logger.log(`Scheduled notification for: ${botId}, at: ${scheduledTime.toDateString()}`);
await this.cacheManager.reset();
}

// dateString = '2020-01-01'
Expand Down Expand Up @@ -349,6 +351,7 @@ export class BotService implements OnModuleInit {
adapter: true;
};
};
schedules: {},
};
}>[]> {
const startTime = performance.now();
Expand Down Expand Up @@ -446,6 +449,7 @@ export class BotService implements OnModuleInit {
adapter: true;
};
};
schedules: {},
};
}> | null> {
const startTime = performance.now();
Expand Down
Loading