saito200
saito200
Explore posts from servers
CDCloudflare Developers
Created by saito200 on 6/8/2024 in #workers-help
Return ok status immediately on async process or not?
My use case: - A webhook intercepts request from telegram bot - Request message is sent to openai and response awaited - Response is sent to Telegram bot with Telegram API - Request returns a 200 response I am using Holo the issue here seems to be that if the 200 response seems to take a while, telegram can retry the request, entering into a never ending loop potentially and pinging openai several times with the same question I think maybe an option is to immediately send a 200 response and then await for openai response (the response is sent to telegram via telegram API, not in the response) However I'm not sure that is okay with Holo or workers (looks like Holo needs to return a response) I.e. - app.post (from telegram) - retrieve user message - send 200 response - send message to OpenAI API - wait for OpenAI response - Send OpenAI response to Telegram API - return I don't think this will work I'm not really a backender, what is the correct way to do this?
4 replies
CCConvex Community
Created by saito200 on 2/3/2024 in #support-community
Auth with chained actions and mutations?
I'm using a mutation that schedules an action. This action runs a bunch of actions one after the other. The first action runs a public mutation which has an authentication guard (a functiont that throws if the user is not auth). This function is throwing an error even if the user is logged in
10 replies
CCConvex Community
Created by saito200 on 2/1/2024 in #support-community
Validator from schema, including internal fields?
I'm passing full DB records to one of my actions and I'm trying to build the validator After some tinkering it looks like this:
export const myAction = internalAction({
args: {
idea: v.object({ ...myValidator, _id: v.id("myTable") })
},
export const myAction = internalAction({
args: {
idea: v.object({ ...myValidator, _id: v.id("myTable") })
},
I am exporting the validator from the schema similar as described here https://stack.convex.dev/types-cookbook The fact that I have to add the _id manually feels a bit awkward to me, but I need the id to be used as a foreign key Am I doing something weird? Is this simply ok? (the action uses some of the fields of the record to create a record for a different table) What I started looking for originally was like a built-in validator that can be extracted from the schema or somewhere else, similar as you can get the DB record type with Doc<"myTable"> but the equivalent for validators, including internal fields
2 replies
CCConvex Community
Created by saito200 on 2/1/2024 in #support-community
How to use the result of a scheduled action?
My mutation schedules an action using await ctx.scheduler.runAfter(0, ...) The action returns a value that then is used by the mutation to write to the DB, or that's what I planned Pseudocode:
myMutation = mutation({
handler: async (ctx) => {
const res = await ctx.scheduler.runAfter(0, ..run action..)
// write res to DB
}
})
myMutation = mutation({
handler: async (ctx) => {
const res = await ctx.scheduler.runAfter(0, ..run action..)
// write res to DB
}
})
But this is not how it works, right? Because the return value of a scheduled action is a promise that resolves to a Id<"_scheduled_functions"> So it looks like I have to schedule the action, and from the action itself run an internal mutation that writes the output of the action to the DB, i.e.: 1. Run public mutation 2. Schedule action 3. Action gets some external data 4. Action runs internal mutation to write to DB Is that second way the "correct way"?
8 replies