Am I doing this correctly? I want to register triggers that fire and upload the latest data to my melisearch cluster only on the production convex:
import {
internalMutation as rawInternalMutation,
mutation as rawMutation,
} from "./_generated/server";
/* eslint-enable no-restricted-imports */
import {
customCtx,
customMutation,
} from "convex-helpers/server/customFunctions";
import { Triggers } from "convex-helpers/server/triggers";
import { internal } from "./_generated/api";
import { DataModel } from "./_generated/dataModel";
import { retrier } from "./retrier";
import { isProduction } from "./utils";
const triggers = new Triggers<DataModel>();
const prod = isProduction();
// register a function to run when a ctx.db.insert, ctx.db.patch, ctx.db.replace, or ctx.db.delete changes the "profiles" table
triggers.register("profiles", async (ctx, change) => {
if (prod) {
await retrier.run(
ctx,
internal.customActions.internal.meiliSearch.syncProfile
.syncProfileToMeili,
{
profileId: change.id,
indexName: "profiles",
}
);
}
});
triggers.register("links", async (ctx, change) => {
if (prod) {
const link = await ctx.db.get(change.id);
await retrier.run(
ctx,
internal.customActions.internal.meiliSearch.syncProfile
.syncProfileToMeili,
{
profileId: link.profileId,
indexName: "profiles",
}
);
}
});
export const mutation = customMutation(rawMutation, customCtx(triggers.wrapDB));
export const internalMutation = customMutation(
rawInternalMutation,
customCtx(triggers.wrapDB)
);