CleanShot.2025-01-09.at.15.35.51.mp4
This demo is a full stack example that demonstrates how to use Trigger.dev Realtime to build a CSV Uploader with live progress updates. The frontend is a Next.js app that allows users to upload a CSV file, which is then processed in the background using Trigger.dev tasks. The progress of the task is streamed back to the frontend in real-time using Trigger.dev Realtime.
- A Next.js app with Trigger.dev for the background tasks.
- UploadThing to handle CSV file uploads
- Trigger.dev Realtime to stream updates to the frontend.
- Uses Bun as the JavaScript runtime and package manager for improved performance.
- After cloning the repo, run
bun installto install the dependencies. - Copy the
.env.examplefile to.envand fill in the required environment variables. If you haven't already, sign up for a free Trigger.dev account here and create a new project. - Copy the project ref from the Trigger.dev dashboard and and add it to the
trigger.config.tsfile. - Run the Next.js server with
bun run dev. - In a separate terminal, run the Trigger.dev dev CLI command with
bun run trigger:dev(it may ask you to authorize the CLI if you haven't already).
Now you should be able to visit http://localhost:3000 and see the app running. Upload a CSV file and watch the progress bar update in real-time!
- View the Trigger.dev task code in the src/trigger/csv.ts file.
- The parent task
csvValidatordownloads the CSV file, parses it, and then splits the rows into multiple batches. It then does abatch.triggerAndWaitto distribute the work thehandleCSVRowtask. - The
handleCSVRowtask "simulates" checking the row for a valid email address and then updates the progress of the parent task usingmetadata.parent. See the Trigger.dev docs for more information on how to use themetadata.parentobject. - The
useRealtimeCSVValidatorhook in the src/hooks/useRealtimeCSVValidator.ts file handles the call touseRealtimeRunto get the progress of the parent task. - The
CSVProcessorcomponent in the src/components/CSVProcessor.tsx file handles the file upload and displays the progress bar, and uses theuseRealtimeCSVValidatorhook to get the progress updates.
To learn more about Trigger.dev Realtime, take a look at the following resources:
- Trigger.dev Documentation - learn about Trigger.dev and its features.
- Metadata docs - learn about the Run Metadata feature of Trigger.dev.
- Batch Trigger docs - learn about the Batch Trigger feature of Trigger.dev.
- Realtime docs - learn about the Realtime feature of Trigger.dev.
- React hooks - learn about the React hooks provided by Trigger.dev.