Skip to content

Commit

Permalink
Pool the server for conversation status
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Nov 24, 2023
1 parent 18ed6d1 commit 62c2db5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
11 changes: 1 addition & 10 deletions src/client/components/ConversationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useQuery } from "@wasp/queries";
import updateConversation from "@wasp/actions/updateConversation";
import getAgentResponse from "@wasp/actions/getAgentResponse";
import getConversations from "@wasp/queries/getConversations";
import { useSocket, useSocketListener } from "@wasp/webSocket";

import ConversationsList from "./ConversationList";
import Loader from "./Loader";
Expand Down Expand Up @@ -42,16 +41,8 @@ export default function ConversationWrapper() {
// @ts-ignore
const { id } = useParams();
const [isLoading, setIsLoading] = useState(false);
// const { socket, isConnected } = useSocket();
// const { refreshChatUI, setRefreshChatUI } = useState(false);
const chatContainerRef = useRef(null);

// useSocketListener("updateChatUI", updateChatUI);

// function updateChatUI() {
// setRefreshChatUI(true);
// }

const loginMsgQuery: any = getQueryParam("msg");
const formInputRef = useCallback(
(node: any) => {
Expand Down Expand Up @@ -80,7 +71,7 @@ export default function ConversationWrapper() {
{
chatId: Number(id),
},
{ enabled: !!id }
{ enabled: !!id, refetchInterval: 1000 }
);

useEffect(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import type {
import type { StripePaymentResult, OpenAIResponse } from "./types";
import Stripe from "stripe";

import { ADS_SERVER_URL } from "./config.js";

const stripe = new Stripe(process.env.STRIPE_KEY!, {
apiVersion: "2022-11-15",
});

// WASP_WEB_CLIENT_URL will be set up by Wasp when deploying to production: https://wasp-lang.dev/docs/deploying
const DOMAIN = process.env.WASP_WEB_CLIENT_URL || "http://localhost:3000";

// Python ADS_SERVER_URL
const ADS_SERVER_URL = process.env.ADS_SERVER_URL || "http://127.0.0.1:9000";

export const stripePayment: StripePayment<void, StripePaymentResult> = async (
_args,
context
Expand Down
2 changes: 2 additions & 0 deletions src/server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ADS_SERVER_URL =
process.env.ADS_SERVER_URL || "http://127.0.0.1:9000";
10 changes: 4 additions & 6 deletions src/server/webSocket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HttpError from "@wasp/core/HttpError.js";

const ADS_SERVER_URL = process.env.ADS_SERVER_URL || "http://127.0.0.1:9000";
import { ADS_SERVER_URL } from "./config.js";

export const webSocketFn = (io, context) => {
io.on("connection", async (socket) => {
Expand All @@ -9,9 +9,9 @@ export const webSocketFn = (io, context) => {
console.log("========");
console.log("a user connected: ", userEmail);

// Check for updates every 5 seconds
// Check for updates every 3 seconds
const updateInterval = setInterval(async () => {
console.log("Check for inprogress tasks update");
console.log("Checking database for inprogress tasks");
const conversations = await context.entities.Conversation.findMany({
where: { userId: socket.data.user.id, status: "inprogress" },
});
Expand Down Expand Up @@ -57,14 +57,12 @@ export const webSocketFn = (io, context) => {
status: conversation_status,
},
});

// io.emit("updateChatUI");
}
} catch (error) {
throw new HttpError(500, error);
}
});
}, 5000);
}, 3000);
}
});
};

0 comments on commit 62c2db5

Please sign in to comment.