Skip to content

prisma/pulse-inngest-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pulse & Inngest Demo Project

This is a simple demo project, to show how you might set up Prisma Pulse with Inngest and NextJS, to run real-time, durable workflows with your serverless app.

This demo repo accompanies the blog article: Build real-time, durable workflows with Pulse and Inngest

Prerequisites

To successfully run the project, you will need the following:

  • An Inngest account
  • The connection string of a Pulse-ready database (if you don't have one yet, you can configure your database following the instructions in our docs or use a Railway template)
  • A Pulse API key which you can get by enabling Pulse in a project in your Prisma Data Platform account (learn more in the docs)

If you would like to deploy the project live, you will also need:

Get started

Pulse streams change events from your Postgres database and submit events to Inngest to trigger workflows and jobs.

NextJS is used in this demo app to be able to run the Inngest workflows, and also to provide a helpful UI for adding records to the database.

Follow the steps below to get both set up and running.

Run locally

Pulse

  1. Go into the pulse directory, and install dependencies: npm install
  2. Rename the .env.example file to .env and set up your environment variables:
    1. DATABASE_URL is the connection string to your database
    2. PULSE_API_KEY is found in your Prisma Data Platform account. See the Pulse documentation for help in getting your API key.
    3. INNGEST_EVENT_KEY and INNGEST_SIGNING_KEY are used to authenticate the service to Inngest in order to submit events. You hopefully set this up in an earlier step.
  3. The Prisma schema file in this project contains a single User model. You can map this model to the database and create the corresponding User table using the following command: npx prisma migrate dev --name init
  4. Generate the Prisma client: npx prisma generate
  5. Run the Pulse service:
     yarn build && yarn start
    

NextJS

  1. Step into the nextjs directory, and install dependencies: npm install
  2. Rename the .env.example file to .env and set up your environment variables:
    • DATABASE_URL is the connection string to your database
  3. Generate the Prisma client: npx prisma generate
  4. Run the NextJS service locally: npm run dev
  5. In a separate tab, run the Inngest service locally: npx inngest-cli@latest dev
  6. Open a browser and navigate to https://localhost:3000

Run a test

You can run this complete demo app by setting up all services and then adding a user to the database. Pulse will detect the database change and submit the event to Inngest, which will, in turn, run a demo workflow.

  1. Make sure all services are running (see instructions above for running each service)
    1. NextJS service
    2. Inngest service
    3. Pulse service
  2. Open https://localhost:3000 in your browser - you should see a simple UI with a form
  3. Enter a user name and email address, then click the button
  4. Watch your terminal logs to observe the events. Prisma Pulse will detect the database change that was applied by NextJS, and submit an event to Inngest. Inngest will pick up the event, and initiate a workflow to onboard the new user. The code will not send real emails, but will simply demonstrate the functionality of the workflow.

Deploy live

Pulse

  1. Add this project to a new GitHub repo (you can use the same one as earlier)
  2. Set up a new project and deploy live with Railway (you can test for free with a Hobby account)
    1. Don’t forget to include the DATABASE_URL, PULSE_API_KEY, INNGEST_SIGNING_KEY and INNGEST_EVENT_KEY environment variables

NextJS

  1. Add this project to a new GitHub repo
  2. Set up a new project and deploy live with Vercel (you can test for free with a Hobby account)
    1. Don’t forget to include your DATABASE_URL
  3. Sync your Vercel App with the Inngest Vercel Integration
  4. Create and save an Inngest Event Key and Signing Key to use in the next step (setting up Pulse)

Run a test

  1. After deploying all services live (according to above instructions), browse to the URL given to your deployment by Vercel. It should look something like your-app.vercel.app
  2. Add a user by entering a name and email address, then click the button
  3. Take a look at the Vercel runtime logs and the Railway logs to observe the events as they are executed

Getting help

Some helpful links in case you need help:

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published