Skip to content

Commit a69f756

Browse files
authored
Added delay example to init.ts so it works with the pages router (#363)
1 parent 0f6e580 commit a69f756

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

.changeset/yellow-rocks-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
Updated example job for the pages router

packages/cli/src/commands/init.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,20 +603,28 @@ export const client = new TriggerClient({
603603
import { eventTrigger } from "@trigger.dev/sdk";
604604
import { client } from "${jobsPathPrefix}trigger";
605605
606-
// your first job
606+
// Your first job
607+
// This Job will be triggered by an event, log a joke to the console, and then wait 5 seconds before logging the punchline
607608
client.defineJob({
609+
// This is the unique identifier for your Job, it must be unique across all Jobs in your project
608610
id: "example-job",
609-
name: "Example Job",
611+
name: "Example Job: a joke with a delay",
610612
version: "0.0.1",
613+
// This is triggered by an event using eventTrigger. You can also trigger Jobs with webhooks, on schedules, and more: https://trigger.dev/docs/documentation/concepts/triggers/introduction
611614
trigger: eventTrigger({
612615
name: "example.event",
613616
}),
614617
run: async (payload, io, ctx) => {
615-
await io.logger.info("Hello world!", { payload });
616-
617-
return {
618-
message: "Hello world!",
619-
};
618+
// This logs a message to the console
619+
await io.logger.info("🧪 Example Job: a joke with a delay");
620+
await io.logger.info("How do you comfort a JavaScript bug?");
621+
// This waits for 5 seconds, the second parameter is the number of seconds to wait, you can add delays of up to a year
622+
await io.wait("Wait 5 seconds for the punchline...", 5);
623+
await io.logger.info("You console it! 🤦");
624+
await io.logger.info(
625+
"✨ Congratulations, You just ran your first successful Trigger.dev Job! ✨"
626+
);
627+
// To learn how to write much more complex (and probably funnier) Jobs, check out our docs: https://trigger.dev/docs/documentation/guides/create-a-job
620628
},
621629
});
622630
`;

0 commit comments

Comments
 (0)