trigger-authoring-tasks

Guides authoring of Trigger.dev backend tasks using the @trigger.dev/sdk API.

1.1k|103|Updated Nov 28, 2024
One-click install
npx skills add https://github.com/VladSez/easy-invoice-pdf --skill trigger-authoring-tasks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trigger-authoring-tasks
Source: https://github.com/VladSez/easy-invoice-pdf/tree/main/.cursor/skills/trigger-authoring-tasks
Command: npx skills add https://github.com/VladSez/easy-invoice-pdf --skill trigger-authoring-tasks

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @trigger.dev/sdk.

What problem does it solve?

Writing background tasks with Trigger.dev involves many subtle API rules—Result objects from triggerAndWait, queue isolation for subtasks, idempotency scoping, and build configuration—and mistakes in these areas cause silent failures or incorrect behavior in production.

Core Features & Use Cases

  • Task Definition Guidance: Covers task(), schemaTask(), the run function and its context, retries, waits, queues, concurrency, and scheduled/cron tasks.
  • Common Mistake Prevention: Documents seven critical pitfalls such as treating wait results as raw output, wrapping triggerAndWait in Promise.all, and calling metadata.set outside run().
  • Version-Pinned Documentation: Directs the AI to read only allowlisted doc pages bundled inside the installed @trigger.dev/sdk package.
  • Use Case: When adding a new email-sequence background task to a /trigger directory, load this skill so the AI writes correct task definitions, triggers them properly from route handlers, and configures trigger.config.ts.

Quick Start

Ask the AI to write a Trigger.dev task that processes a payload with retries and a concurrency-limited queue inside your project's trigger directory.

Frequently Asked Questions about trigger-authoring-tasks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a Trigger.dev task with schema validation?

Use schemaTask() from @trigger.dev/sdk with a schema parser for the payload and a run function containing your logic. Always import from @trigger.dev/sdk, never the deprecated @trigger.dev/sdk/v3 alias or @trigger.dev/core.

How do I trigger a Trigger.dev task from backend code?

Import only the task's type, then call tasks.trigger<typeof myTask>("task-id", payload) in your route handler. Importing the task instance directly into backend code is incorrect.

Why does triggerAndWait not return my task output directly?

triggerAndWait and wait.forToken return a Result object, not the raw output. Check result.ok and read result.output, or call .unwrap(), before using the returned values.

Can I run multiple Trigger.dev subtasks in parallel with Promise.all?

No, wrapping triggerAndWait calls in Promise.all is incorrect. Use batchTriggerAndWait with an array of payloads, or trigger them sequentially in a for-loop.

Do child tasks inherit the parent task's queue and metadata?

No, subtasks run on their own queue with their own concurrency limit and do not see parent metadata. Pass metadata explicitly via { metadata: metadata.current() } or push values up with metadata.parent.*.

How do I make Trigger.dev task triggering idempotent?

Create a scoped key with idempotencyKeys.create("my-key", { scope: "global" }) rather than relying on a raw string key, which is only globally scoped by default in v4.3.0 and earlier.