Skip to content

04 : background jobs#2

Open
AnkitRewar11 wants to merge 1 commit into
mainfrom
04-background-jobs
Open

04 : background jobs#2
AnkitRewar11 wants to merge 1 commit into
mainfrom
04-background-jobs

Conversation

@AnkitRewar11
Copy link
Copy Markdown
Owner

@AnkitRewar11 AnkitRewar11 commented Nov 14, 2025

Summary by CodeRabbit

  • New Features

    • Added background job processing for improved performance and asynchronous task handling.
    • Introduced toast notifications providing real-time feedback on user actions.
    • Added button to trigger background jobs from the main interface.
  • Removed

    • Removed legacy client component.

@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vibe Error Error Nov 14, 2025 11:07am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 14, 2025

Walkthrough

This PR integrates Inngest background job queue functionality into the application. It adds an Inngest client and function definition, exposes a new TRPC mutation to trigger background jobs, wires an Inngest API route handler, and refactors the page component from server-side prefetching to client-side event triggering with toast notifications.

Changes

Cohort / File(s) Summary
Dependency Updates
package.json
Added Inngest runtime dependency (^3.45.1)
Inngest Infrastructure
src/inngest/client.ts, src/inngest/functions.ts
Created Inngest client singleton and defined a background function (helloWorld) that processes events with async steps (sleep operations) and returns formatted messages.
API Route Integration
src/app/api/inngest/route.ts
New Next.js API route that serves Inngest functions, exporting GET, POST, and PUT handlers via serve() call.
TRPC Router Updates
src/trpc/routers/_app.ts
Added new invoke mutation to send events to Inngest; refactored createAI query to use destructured input parameter.
UI & Layout Changes
src/app/layout.tsx
Integrated Toaster component from Sonner for toast notifications.
Page Component Refactor
src/app/page.tsx
Converted from async server component with server-side prefetching to client component with TRPC mutation trigger and toast feedback.
Removed Components
src/app/client.tsx
Deleted Client React component that used TRPC and React Query for data fetching.

Sequence Diagram

sequenceDiagram
    participant User
    participant ClientUI as Client (page.tsx)
    participant TRPC
    participant Inngest API
    participant InngestWorker as Inngest Worker

    User->>ClientUI: Click button
    ClientUI->>TRPC: invoke mutation (text)
    TRPC->>Inngest API: POST event (test/hello.world)
    Inngest API->>InngestWorker: Queue background job
    InngestWorker->>InngestWorker: step.sleep (10s)
    InngestWorker->>InngestWorker: step.sleep (5s)
    Inngest API-->>TRPC: { ok: "success" }
    TRPC-->>ClientUI: Mutation success
    ClientUI->>ClientUI: Show toast
    ClientUI->>User: Display success feedback
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inngest client and function definition: Verify correct event schema, step configuration, and return values align with backend expectations.
  • TRPC invoke mutation: Confirm event payload structure matches the Inngest function's expected input (test/hello.world event with email data).
  • Page component refactor: Review async-to-client transition and ensure TRPC hook usage and error handling are complete.
  • API route wiring: Validate that the Inngest route correctly serves the registered functions and exports appropriate HTTP methods.

Poem

🐰 A rabbit bounced through Inngest gates,
With background jobs that hardly wait,
Toast notifications pop and gleam,
Client mutations fulfill each dream,
Async steps now process with grace! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '04 : background jobs' directly and clearly summarizes the main changes across all modified files, which center on integrating Inngest for background job processing.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 04-background-jobs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AnkitRewar11
Copy link
Copy Markdown
Owner Author

..

@AnkitRewar11
Copy link
Copy Markdown
Owner Author

.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
src/inngest/client.ts (1)

4-4: Replace the generic app ID with a meaningful identifier.

The hardcoded ID "my-app" is too generic. Consider using a more descriptive identifier that reflects your application name, or use an environment variable for different environments.

Apply this diff to use an environment variable with a fallback:

-export const inngest = new Inngest({ id: "my-app" });
+export const inngest = new Inngest({ 
+  id: process.env.INNGEST_APP_ID || "vibe-app",
+  eventKey: process.env.INNGEST_EVENT_KEY,
+  signingKey: process.env.INNGEST_SIGNING_KEY,
+});
src/app/page.tsx (2)

8-8: Follow JavaScript naming conventions.

The variable Invoke should follow camelCase convention for variables (start with lowercase).

-  const Invoke = useMutation(trpc.invoke.mutationOptions({
+  const invoke = useMutation(trpc.invoke.mutationOptions({

And update the references:

-      <button disabled = {Invoke.isPending} onClick={()=> Invoke.mutate({text : "Ankit"})} className="px-4 py-2 bg-black text-white rounded hover:bg-blue-700">
+      <button disabled={invoke.isPending} onClick={() => invoke.mutate({text: "Ankit"})} className="px-4 py-2 bg-black text-white rounded hover:bg-blue-700">

16-18: Remove hardcoded value and improve button formatting.

The button has a hardcoded value "Ankit" which should be configurable or removed. Also, fix spacing issues in the JSX attributes.

Apply this diff to improve the button:

-      <button disabled = {Invoke.isPending} onClick={()=> Invoke.mutate({text : "Ankit"})} className="px-4 py-2 bg-black text-white rounded hover:bg-blue-700">
+      <button 
+        disabled={invoke.isPending} 
+        onClick={() => invoke.mutate({text: "user"})} 
+        className="px-4 py-2 bg-black text-white rounded hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
+      >
-        Invoke Background Job
+        {invoke.isPending ? "Invoking..." : "Invoke Background Job"}
       </button>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbac601 and bc39b55.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/app/api/inngest/route.ts (1 hunks)
  • src/app/client.tsx (0 hunks)
  • src/app/layout.tsx (2 hunks)
  • src/app/page.tsx (1 hunks)
  • src/inngest/client.ts (1 hunks)
  • src/inngest/functions.ts (1 hunks)
  • src/trpc/routers/_app.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/app/client.tsx
🧰 Additional context used
🧬 Code graph analysis (4)
src/inngest/functions.ts (1)
src/inngest/client.ts (1)
  • inngest (4-4)
src/app/api/inngest/route.ts (2)
src/inngest/client.ts (1)
  • inngest (4-4)
src/inngest/functions.ts (1)
  • helloWorld (3-16)
src/trpc/routers/_app.ts (2)
src/trpc/init.ts (2)
  • createTRPCRouter (21-21)
  • baseProcedure (23-23)
src/inngest/client.ts (1)
  • inngest (4-4)
src/app/page.tsx (1)
src/trpc/server.tsx (1)
  • trpc (10-14)
🔇 Additional comments (3)
src/app/layout.tsx (1)

4-4: LGTM! Toaster integration is correct.

The Toaster component from sonner is properly imported and placed in the layout, enabling toast notifications throughout the application.

Also applies to: 35-35

src/trpc/routers/_app.ts (1)

27-30: LGTM! Input destructuring improves readability.

The refactoring to destructure the input parameter makes the code cleaner and more consistent.

package.json (1)

53-53: No issues found—inngest@3.45.1 is current and secure.

Verification confirms no public CVEs or recorded security vulnerabilities for inngest version 3.45.1, and the specified version matches the latest available release.

import { inngest } from "@/inngest/client";
import { helloWorld } from "@/inngest/functions";

// Create an API that serves zero functions
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the misleading comment.

The comment states "Create an API that serves zero functions", but the code actually registers the helloWorld function.

Apply this diff to correct the comment:

-// Create an API that serves zero functions
+// Create an API that serves Inngest functions
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Create an API that serves zero functions
// Create an API that serves Inngest functions
🤖 Prompt for AI Agents
In src/app/api/inngest/route.ts around line 5, the inline comment "Create an API
that serves zero functions" is misleading because the file registers the
helloWorld function; update the comment to accurately reflect that this API
registers/serves the helloWorld function (e.g., "Create an API that serves the
helloWorld function" or similar), keeping tone concise and matching surrounding
comment style.

Comment thread src/inngest/functions.ts
Comment on lines +9 to +14
// simulate processing the file
await step.sleep("wait-a-moment", "10s");

// simulate uploading the file
await step.sleep("wait-a-moment", "5s");
return { message: `Hello ${event.data.email}!` };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Rename the misleading field and update comments.

The field name event.data.email is misleading since it receives arbitrary text (e.g., "Ankit"), not an email address. The comments also mention "file processing" when the function is just simulating delays.

Consider renaming for clarity:

-    // simulate processing the file
+    // simulate processing step 1
     await step.sleep("process-file", "10s");

-    // simulate uploading the file
+    // simulate processing step 2
     await step.sleep("upload-file", "5s");
-    return { message: `Hello ${event.data.email}!` };
+    return { message: `Hello ${event.data.name}!` };

Note: This change requires updating the corresponding field in src/trpc/routers/_app.ts from email: input.text to name: input.text.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/inngest/functions.ts around lines 9 to 14, the handler uses
event.data.email and comments referencing "file processing" which are
misleading; rename the field to event.data.name, update the return to use `Hello
${event.data.name}!`, and change comments to reflect simulated delays rather
than file processing; also update the corresponding mapping in
src/trpc/routers/_app.ts by changing `email: input.text` to `name: input.text`
so the input field names remain consistent.

Comment thread src/inngest/functions.ts
Comment on lines +10 to +13
await step.sleep("wait-a-moment", "10s");

// simulate uploading the file
await step.sleep("wait-a-moment", "5s");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix duplicate step IDs.

Both step.sleep calls use the same step ID "wait-a-moment". Inngest requires unique step IDs within a function to properly track execution state. This will cause runtime issues.

Apply this diff to use unique step IDs:

-    await step.sleep("wait-a-moment", "10s");
+    await step.sleep("process-file", "10s");

     // simulate uploading the file
-    await step.sleep("wait-a-moment", "5s");
+    await step.sleep("upload-file", "5s");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await step.sleep("wait-a-moment", "10s");
// simulate uploading the file
await step.sleep("wait-a-moment", "5s");
await step.sleep("process-file", "10s");
// simulate uploading the file
await step.sleep("upload-file", "5s");
🤖 Prompt for AI Agents
In src/inngest/functions.ts around lines 10 to 13 there are duplicate step IDs:
both await step.sleep calls use "wait-a-moment", which will break Inngest's step
tracking; update the second (or both) step IDs to be unique (e.g.,
"wait-a-moment-1" and "wait-a-moment-2" or similar distinct names) so each step
has a unique identifier and keep any references consistent.

Comment thread src/trpc/routers/_app.ts
Comment on lines +13 to +18
await inngest.send({
name: "test/hello.world",
data: {
email: input.text,
},
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for the Inngest event emission.

The inngest.send call is not wrapped in error handling. If the event emission fails, the mutation will throw an unhandled error without a meaningful response.

Apply this diff to add error handling:

-      await inngest.send({
-        name: "test/hello.world",
-        data: {
-          email: input.text,
-        },
-      });
-      return { ok: "success" };
+      try {
+        await inngest.send({
+          name: "test/hello.world",
+          data: {
+            email: input.text,
+          },
+        });
+        return { ok: "success" };
+      } catch (error) {
+        throw new Error("Failed to invoke background job");
+      }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/trpc/routers/_app.ts around lines 13 to 18, the await inngest.send({...})
call is unguarded and can throw an unhandled error; wrap the send call in a
try/catch, log the caught error (with context and the input data), and convert
it into a proper tRPC error response (e.g., throw a TRPCError with code
"INTERNAL" and a clear message) so the mutation returns a meaningful error
instead of crashing; ensure the handler still returns success when send
succeeds.

Comment thread src/trpc/routers/_app.ts
await inngest.send({
name: "test/hello.world",
data: {
email: input.text,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Rename the misleading field from "email" to "name" or "text".

The field name email is misleading since it receives arbitrary text like "Ankit", not an email address. This is inconsistent with how the field is used.

This requires coordinated changes:

  1. In this file:
         data: {
-          email: input.text,
+          name: input.text,
         },
  1. In src/inngest/functions.ts (Line 14):
-    return { message: `Hello ${event.data.email}!` };
+    return { message: `Hello ${event.data.name}!` };

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/trpc/routers/_app.ts around line 16 the input field is named "email" but
it carries arbitrary text (e.g., "Ankit"); rename this field to a descriptive
name such as "name" or "text" and update all usages accordingly. Change the
input schema key, any places reading input.email to input.name (or input.text),
and update types/interfaces. Also update the referenced src/inngest/functions.ts
(around line 14) to use the new field name and adjust any event payloads or
handlers that expect "email" so they consume the new key consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant