-
-
Save johanneskares/67da1de0d4a127381124326c251ae6f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Current Approach | |
import { Inngest } from "inngest"; | |
const inngest = new Inngest({ id: "my-app" }); | |
// This function will be invoked by Inngest via HTTP any time | |
// the "app/user.signup" event is sent to to Inngest | |
export default inngest.createFunction( | |
{ id: "user-onboarding-communication" }, | |
{ event: "app/user.signup" }, | |
async ({ event, step }) => { | |
await step.run("Send welcome email", async () => { | |
await sendEmail({ | |
email: event.data.email, | |
template: "welcome", | |
}); | |
}); | |
} | |
); | |
// 2. Proposal | |
import { router} from "./trpc" | |
import { procedure } from "inngest"; | |
import { z } from "zod"; | |
export const inngestRouter = router({ | |
// Example from above, auto generated event ID | |
userOnboardCommunication: procedure({ // settings }) | |
.input(z.object({ email: z.string().email() })) | |
.query(async { step, input} => { | |
await step.run("Send welcome email", async () => { | |
await sendEmail({ | |
email: input.email, | |
template: "welcome", | |
}); | |
}); | |
}), | |
// External events, reusable events, defined on router, backwards compatible with current reusable event system. | |
legacyEvent: procedure | |
.eventInput("app/user.signup") | |
.query(async { step, input} => { | |
await step.run("Send welcome email", async () => { | |
await sendEmail({ | |
email: event.data.email, | |
template: "welcome", | |
}); | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment