-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add autoSyncDataSources column to Bot table and update related…
… code
- Loading branch information
Showing
14 changed files
with
195 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "DialoqbaseSettings" ADD COLUMN "refetchDatasource" BOOLEAN NOT NULL DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Bot" ADD COLUMN "autoSyncDataSources" BOOLEAN DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { getSettings } from "../utils/common"; | ||
import { queue } from "../queue/q"; | ||
const prisma = new PrismaClient(); | ||
|
||
async function processDatasourceCron() { | ||
try { | ||
await prisma.$connect(); | ||
const setting = await getSettings(prisma); | ||
|
||
if (!setting.refetchDatasource) { | ||
return; | ||
} | ||
|
||
console.log("[CRON] Processing datasource cron"); | ||
|
||
|
||
const dataSources = await prisma.botSource.findMany({ | ||
where: { | ||
bot: { | ||
autoSyncDataSources: true | ||
}, | ||
type: { | ||
in: [ | ||
"website", | ||
"crawl", | ||
"sitemap", | ||
] | ||
} | ||
}, | ||
include: { | ||
bot: true | ||
} | ||
}) | ||
|
||
for (const dataSource of dataSources) { | ||
|
||
await prisma.botDocument.deleteMany({ | ||
where: { | ||
botId: dataSource.botId, | ||
sourceId: dataSource.id, | ||
}, | ||
}); | ||
await queue.add( | ||
"process", | ||
[ | ||
{ | ||
...dataSource, | ||
embedding: dataSource.bot.embedding, | ||
}, | ||
], | ||
{ | ||
jobId: dataSource.id, | ||
removeOnComplete: true, | ||
removeOnFail: true, | ||
} | ||
); | ||
} | ||
|
||
|
||
console.log("[CRON] Finished processing datasource cron"); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} | ||
|
||
export { processDatasourceCron }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters