Skip to content

Commit

Permalink
Update package versions and fix error handling in data source deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
n4ze3m committed Apr 17, 2024
1 parent 8214052 commit c4ca301
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"private": true,
"version": "1.7.9",
"version": "1.8.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
17 changes: 12 additions & 5 deletions app/ui/src/components/Bot/DS/DsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ export const DsTable = ({
message: "Data source deleted successfully",
});
},
onError: () => {
onError: (err: any) => {
notification.error({
message: "Error while deleting data source",
message:
err?.response?.data?.message ||
err?.response?.data?.error ||
"Error while deleting data source",
});
},
}
Expand All @@ -96,9 +99,12 @@ export const DsTable = ({
message: "Data source updated successfully",
});
},
onError: () => {
onError: (err: any) => {
notification.error({
message: "Error while updating data source",
message:
err?.response?.data?.message ||
err?.response?.data?.error ||
"Error while deleting data source",
});
},
}
Expand All @@ -109,7 +115,8 @@ export const DsTable = ({
<div className="sm:flex sm:items-center">
<div className="sm:flex-auto">
<h1 className="text-xl font-semibold text-gray-900 dark:text-white">
Data Sources</h1>
Data Sources
</h1>
<p className="mt-2 text-sm text-gray-700 dark:text-gray-400">
List of data sources that are currently being used by your bot.
</p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dialoqbase",
"version": "1.7.9",
"version": "1.8.0",
"description": "Create chatbots with ease",
"scripts": {
"ui:dev": "pnpm run --filter ui dev",
Expand Down
14 changes: 13 additions & 1 deletion server/src/handlers/api/v1/bot/bot/api.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,21 @@ export const addNewSourceByIdBulkHandler = async (
maxDepth: source.maxDepth,
maxLinks: source.maxLinks,
options: source.options,
id: botSource.id,
});
}
await request.server.queue.add('process', queueSource);

await request.server.queue.addBulk(
queueSource.map((source) => ({
data: [source],
name: "process",
opts: {
jobId: source.id,
removeOnComplete: true,
removeOnFail: true,
},
}))
);

return {
success: true,
Expand Down
19 changes: 13 additions & 6 deletions server/src/handlers/api/v1/bot/bot/delete.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TelegramBot from "../../../../../integration/telegram";

export const deleteSourceByIdHandler = async (
request: FastifyRequest<GetSourceByIds>,
reply: FastifyReply,
reply: FastifyReply
) => {
const prisma = request.server.prisma;
const bot_id = request.params.id;
Expand Down Expand Up @@ -38,9 +38,16 @@ export const deleteSourceByIdHandler = async (
}

if (botSource.isPending) {
return reply.status(400).send({
message: "Source is in progress",
});
const job = await request.server.queue.getJob(botSource.id);
if (job) {
const isActive = await job.isActive();
if (isActive) {
return reply.status(400).send({
message: "Source is being processed, cannot delete it now",
});
}
await job.remove();
}
}

await prisma.botDocument.deleteMany({
Expand All @@ -63,7 +70,7 @@ export const deleteSourceByIdHandler = async (

export const deleteBotByIdHandler = async (
request: FastifyRequest<GetBotRequestById>,
reply: FastifyReply,
reply: FastifyReply
) => {
const prisma = request.server.prisma;
const id = request.params.id;
Expand Down Expand Up @@ -130,7 +137,7 @@ export const deleteBotByIdHandler = async (
await prisma.botPlayground.deleteMany({
where: {
botId: bot.id,
}
},
});

await prisma.bot.delete({
Expand Down
75 changes: 53 additions & 22 deletions server/src/handlers/api/v1/bot/bot/post.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,23 @@ export const createBotHandler = async (
},
});

await request.server.queue.add("process", [
await request.server.queue.add(
"process",
[
{
...botSource,
embedding,
maxDepth: request.body.maxDepth,
maxLinks: request.body.maxLinks,
options: request.body.options,
},
],
{
...botSource,
embedding,
maxDepth: request.body.maxDepth,
maxLinks: request.body.maxLinks,
options: request.body.options,
},
]);
jobId: botSource.id,
removeOnComplete: true,
removeOnFail: true,
}
);
return {
id: bot.id,
};
Expand Down Expand Up @@ -211,15 +219,21 @@ export const addNewSourceByIdHandler = async (
});
}

await request.server.queue.add('process',[
await request.server.queue.add(
"process",
[
{
...botSource,
embedding: bot.embedding,
maxDepth: request.body.maxDepth,
maxLinks: request.body.maxLinks,
options: request.body.options,
},
],
{
...botSource,
embedding: bot.embedding,
maxDepth: request.body.maxDepth,
maxLinks: request.body.maxLinks,
options: request.body.options,
},
]);
jobId: botSource.id,
}
);
return {
id: bot.id,
};
Expand Down Expand Up @@ -258,6 +272,16 @@ export const refreshSourceByIdHandler = async (
message: "Source not found",
});
}
// check if the source is already in pending state

const isInJob = await request.server.queue.getJob(botSource.id);
if (isInJob) {
if (isInJob.isWaiting() || isInJob.isActive()) {
return reply.status(400).send({
message: "Source is already in pending state",
});
}
}

await prisma.botSource.update({
where: {
Expand All @@ -275,13 +299,20 @@ export const refreshSourceByIdHandler = async (
sourceId: source_id,
},
});
await request.server.queue.add('process',[
await request.server.queue.add(
"process",
[
{
...botSource,
embedding: bot.embedding,
},
],
{
...botSource,
embedding: bot.embedding,
},
]);

jobId: botSource.id,
removeOnComplete: true,
removeOnFail: true,
}
);
return {
id: bot.id,
};
Expand Down
49 changes: 38 additions & 11 deletions server/src/handlers/api/v1/bot/bot/upload.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,20 @@ export const createBotFileHandler = async (
},
});

await request.server.queue.add("process", [
await request.server.queue.add(
"process",
[
{
...botSource,
embedding: bot.embedding,
},
],
{
...botSource,
embedding: bot.embedding,
},
]);
jobId: botSource.id,
removeOnComplete: true,
removeOnFail: true,
}
);
}

return reply.status(200).send({
Expand Down Expand Up @@ -210,12 +218,20 @@ export const addNewSourceFileByIdHandler = async (
});
}

await request.server.queue.add("process", [
await request.server.queue.add(
"process",
[
{
...botSource,
embedding: bot.embedding,
},
],
{
...botSource,
embedding: bot.embedding,
},
]);
jobId: botSource.id,
removeOnComplete: true,
removeOnFail: true,
}
);
}

return {
Expand Down Expand Up @@ -274,10 +290,21 @@ export const addNewSourceFileByIdBulkHandler = async (
queueSource.push({
...botSource,
embedding: bot.embedding,
id: botSource.id,
});
}

await request.server.queue.add("process", queueSource);
await request.server.queue.addBulk(
queueSource.map((source) => ({
data: [source],
name: "process",
opts: {
jobId: source.id,
removeOnComplete: true,
removeOnFail: true,
},
}))
);

return {
source_ids: queueSource.map((source) => source.id),
Expand Down

0 comments on commit c4ca301

Please sign in to comment.