Indie Kit DocsIndie Kit Docs
Tutorials

Running Scheduled Jobs

Learn how to create and manage background jobs using Inngest in your Indie Kit application

Running Scheduled Jobs ⏰

Let's learn how to create and manage background jobs using Inngest! 🚀

Creating Background Jobs 🛠️

  1. Create a new function in src/lib/inngest/functions/hello-world.ts:

    import { inngest } from "@/lib/inngest/client";
     
    // Define your function
    export const helloWorld = inngest.createFunction(
      { name: "Hello World" },
      { event: "test/hello.world" },
      async ({ event, step }) => {
        await step.sleep("wait-a-bit", "1m");
        return { message: "Hello, World!" };
      }
    );
  2. Register your function in src/lib/inngest/functions/index.ts:

    import { helloWorld } from "./hello-world";
     
    export const functions = [
      helloWorld,
      // Add more functions here
    ];

Sending Events 📤

Trigger your background jobs by sending events:

import { inngest } from "@/lib/inngest/client";
 
// Send an event
await inngest.send({
  name: "storefront/cart.checkout.completed",
  data: {
    cartId: "ed12c8bde",
    itemIds: ["9f08sdh84", "sdf098487"],
    account: {
      id: 123,
      email: "test@example.com",
    },
  },
});

Monitoring Jobs 📊

  1. Local Development:

    • Visit Inngest dashboard at http://localhost:8288
    • Monitor job executions
    • Debug events and functions
  2. Production:

    • Use Inngest Cloud dashboard
    • Set up alerts
    • View execution history

Advanced Features 🎯

Best Practices 💡

  1. Function Organization

    • One function per file
    • Clear, descriptive names
    • Register all functions in index.ts
  2. Event Design

    • Use consistent naming
    • Include necessary data
    • Version events if needed
  3. Error Handling

    • Implement retries
    • Log errors properly
    • Set up monitoring
  4. Testing

    • Test locally first
    • Use development environment
    • Monitor execution times

Example Use Cases 🌟

  • Send welcome emails
  • Process uploads
  • Generate reports
  • Clean up old data
  • Schedule notifications
  • Sync external services

Now your Indie Kit application is ready to handle background jobs efficiently! 🎉

On this page