chore: invoke function from code in inngest

This commit is contained in:
javayhu 2025-06-25 00:29:28 +08:00
parent 249fd63405
commit 09545c4b6e
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import { inngest } from '@/inngest/client';
import { NextResponse } from 'next/server';
// Opt out of caching; every request should send a new event
export const dynamic = 'force-dynamic';
// Create a simple async Next.js API route handler
export async function GET() {
console.log('Send event to Inngest start');
// Send your event payload to Inngest
await inngest.send({
name: 'test/hello.world',
data: {
email: 'testUser@example.com',
},
});
console.log('Send event to Inngest end');
return NextResponse.json({ message: 'Event sent!' });
}

View File

@ -4,7 +4,9 @@ export const helloWorld = inngest.createFunction(
{ id: 'hello-world' }, { id: 'hello-world' },
{ event: 'test/hello.world' }, { event: 'test/hello.world' },
async ({ event, step }) => { async ({ event, step }) => {
console.log('Hello World function start');
await step.sleep('wait-a-moment', '1s'); await step.sleep('wait-a-moment', '1s');
console.log('Hello World function end');
return { message: `Hello ${event.data.email}!` }; return { message: `Hello ${event.data.email}!` };
} }
); );