#Error in retrier

7 messages · Page 1 of 1 (latest)

full gulch
#

Why does this give me an error:

await retrier.run(internal.customActions.internal.meiliSearch.syncProfile.syncProfileToMeili, {
        profileId: change.id,
        indexName: "profiles"
    });

But this works fine?

    await ctx.scheduler.runAfter(0, internal.customActions.internal.meiliSearch.syncProfile.syncProfileToMeili, {
        profileId: change.id,
        indexName: "profiles"
    });

I get this error:

Argument of type 'FunctionReference<"action", "internal", { profileId: Id<"profiles">; indexName: string; }, { success: boolean; }, string>' is not assignable to parameter of type 'RunMutationCtx'.
Property 'runMutation' is missing in type 'FunctionReference<"action", "internal", { profileId: Id<"profiles">; indexName: string; }, { success: boolean; }, string>' but required in type 'RunMutationCtx'.

full cedarBOT
#

Hi @full gulch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error you're encountering is related to how the action retrier component works compared to the scheduler in Convex.

The issue is that retrier.run() expects a context object as its first parameter, not a function reference. Based on the error message, it seems the retrier is looking for a RunMutationCtx object with a runMutation method, but you're passing a function reference instead.

According to the action retrier documentation, the correct way to use retrier.run() is:

const runId = await retrier.run(ctx, internal.index.exampleAction, {
  foo: "bar",
});

Notice that the first parameter is the context (ctx), followed by the function reference, and then the arguments.

In your case, the correct usage would be:

await retrier.run(ctx, internal.customActions.internal.meiliSearch.syncProfile.syncProfileToMeili, {
  profileId: change.id,
  indexName: "profiles"
});

The scheduler's runAfter() method has a different signature, which is why your second example works fine:

await ctx.scheduler.runAfter(0, internal.customActions.internal.meiliSearch.syncProfile.syncProfileToMeili, {
  profileId: change.id,
  indexName: "profiles"
});

The action retrier is designed to provide automatic retries for actions that might fail, while the scheduler is meant for scheduling functions to run at a specific time or after a delay. They serve different purposes and have different APIs.

For more details on how to use the action retrier, you can refer to the Action Retrier documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@full gulch Kapa.ai is still learning and improving, please let me know how I did by reacting below.

full gulch
#

triggers.register("profiles", async (ctx, change) => {
if (isProduction()) {
await retrier.run(ctx, internal.customActions.internal.meiliSearch.syncProfile.syncProfileToMeili, {
profileId: change.id,
indexName: "profiles"
});
}
});

This is within a trigger will I get the document id correctly by using change.id? @full cedar

full cedarBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Yes, using change.id within a trigger is the correct way to access the document ID of the changed document.

According to the Convex triggers documentation, the trigger function receives a change object that contains information about the document that was changed, including its ID. This is exactly how you should reference the document ID in a trigger function.

Looking at your code, you're correctly using change.id to pass the profile document's ID to your action. This pattern is demonstrated in several examples in the Convex documentation, particularly in the section about asynchronous debounced processing:

triggers.register("users", async (ctx, change) => {
  // ...
  scheduled[change.id] = await ctx.scheduler.runAfter(
    0,
    internal.users.updateClerkUser,
    { id: change.id, user: change.newDoc },
  );
});

Database Triggers shows this exact pattern of using change.id within triggers to reference the document ID.

Your implementation with the retrier is also correct - you're passing the context (ctx), the function reference, and then the arguments object with the profile ID and index name, which matches the expected API for the retrier as shown in the Action Retrier documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: