Back to jobs

Delay example Job

Trigger: eventTrigger

Logs a joke, waits 5 seconds, and then logs the punchline.

Integrations:

None

/src/delayExampleJoke

Scheduled

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
3
const client = new TriggerClient({ id: "jobs-showcase" });
4
5
// This Job will be triggered by an event, log a joke, and then wait 5 seconds before logging the punchline
6
client.defineJob({
7
// This is the unique identifier for your Job, it must be unique across all Jobs in your project
8
id: "delay-example-joke",
9
name: "Delay example joke",
10
version: "1.0.0",
11
trigger: eventTrigger({
12
name: "example.event",
13
}),
14
run: async (payload, io, ctx) => {
15
await io.logger.info("🧪 Example Job: a joke with a delay");
16
await io.logger.info("How do you comfort a JavaScript bug?");
17
await io.wait("Wait 5 seconds for the punchline...", 5);
18
await io.logger.info("You console it! 🤦");
19
await io.logger.info(
20
"✨ Congratulations, You just ran your first successful Trigger.dev Job! ✨"
21
);
22
// To learn how to write much more complex (and probably funnier) Jobs,
23
// check out our docs: https://trigger.dev/docs/documentation/guides/create-a-job
24
},
25
});
26
27
// These lines can be removed if you don't want to use express
28
import { createExpressServer } from "@trigger.dev/express";
29
createExpressServer(client);