diff --git a/src/actions/hello-world-task.ts b/src/actions/hello-world-task.ts new file mode 100644 index 0000000..1c8eb89 --- /dev/null +++ b/src/actions/hello-world-task.ts @@ -0,0 +1,20 @@ +'use server'; + +import type { helloWorldTask } from '@/trigger/hello-world'; +import { tasks } from '@trigger.dev/sdk/v3'; + +export async function myTask() { + try { + const handle = await tasks.trigger( + 'hello-world', + 'James' + ); + + return { handle }; + } catch (error) { + console.error(error); + return { + error: 'something went wrong', + }; + } +} diff --git a/src/trigger/hello-world.ts b/src/trigger/hello-world.ts new file mode 100644 index 0000000..609b681 --- /dev/null +++ b/src/trigger/hello-world.ts @@ -0,0 +1,14 @@ +import { logger, task, wait } from '@trigger.dev/sdk/v3'; + +export const helloWorldTask = task({ + id: 'hello-world', + run: async (payload: any, { ctx }) => { + logger.log('Hello, world!', { payload, ctx }); + + await wait.for({ seconds: 5 }); + + return { + message: 'Hello, world!', + }; + }, +});