All skills
upstash avatar

/upstash-workflow-js

@36daab8
by upstashupstash/skills27 stars
7

Work with the @upstash/workflow TypeScript/JavaScript SDK for durable, long-running workflows in serverless functions, multi-step processes that survive timeouts, retries, and restarts (built on QStash). Use when defining a workflow endpoint with serve(), running steps with context.run, sleeping for minutes to days without holding a function open, calling external APIs with context.call, waiting for an external event or webhook, invoking other workflows, configuring retries, failure callbacks, and a DLQ, controlling concurrency, rate, and parallelism, triggering, cancelling, or inspecting runs with the Workflow client, building AI agents and orchestrators, human-in-the-loop approvals, realtime updates, local development with the QStash dev server, adding middleware, or migrating workflows safely. Also use when the user asks for durable execution, step functions, saga or orchestration patterns, background jobs with checkpoints, or long-running tasks on Vercel, Next.js, Cloudflare Workers, or other serverless platforms.

Use this Skill: https://skilld.dev/gh/upstash/skills/upstash-workflow-js

This session only. Nothing lands on disk.

featureswebhooks.md

≈629 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Webhooks

This skill teaches agents how to use webhooks inside Upstash Workflow to pause execution, wait for external callbacks, and resume reliably. It covers creation, waiting, validation, and multi-step usage.


Key Concepts

• Webhook URLs are unique per context.createWebhook() call. • Workflow execution pauses when calling context.waitForWebhook() until the webhook receives a request or times out. • Lookback protection ensures the workflow still receives early webhook calls. • Workflows remain dormant during the waiting period, avoiding compute cost. • Webhooks are ideal for third‑party APIs that support callback URLs.


Core Workflow: Create → Call External API → Wait → Resume

Below is a consolidated example showing: • Creating a webhook • Passing it to an external API • Handling the callback • Waiting for multiple updates • Error/timeout handling

import { serve } from "@upstash/workflow/nextjs";

export const { POST } = serve(async (context) => {
  // Create a unique webhook for this workflow
  const webhook = await context.createWebhook("create webhook");

  // Trigger an external service, sending it the callback URL
  await context.call("trigger-external", {
    url: "https://api.example.com/process",
    method: "POST",
    body: { webhookUrl: webhook.webhookUrl },
  });

  // Loop: wait for progress updates until service signals completion
  let updates = [];
  while (true) {
    const res = await context.waitForWebhook(`wait update`, webhook, "5m");

    if (res.timeout) break; // no progress received

    const req = res.request;
    const payload = await req.json();
    updates.push(payload);

    if (req.headers.get("x-task-finished") === "true") break;
  }

  return updates;
});

Webhook Reliability: Lookback Protection

Common pitfall: external systems may call the webhook before the workflow reaches waitForWebhook().

Upstash automatically stores early webhook calls. The next waitForWebhook() will immediately resolve with the stored request.

This avoids race conditions and eliminates the need for manual buffering.


When to Use Webhooks vs. Wait for Event

Use webhooks when: • integrating with third‑party APIs • the external system invokes a callback URL • you need race‑condition‑safe behavior

Use Wait for Event when: • you control the notifying system and can use the Workflow Client • you don't need lookback semantics

Source: SKILL.md on GitHub

1 warning17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill is a comprehensive documentation and implementation guide for the Upstash Workflow SDK. It covers durable serverless workflows, agent orchestration, and reliability features. All identified external resources and tool downloads are official components of the Upstash platform or well-known development services. No security issues or malicious patterns were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: MEDIUM · 1 issue

Signed by skilld at 36daab8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last month
metadata
{
  "author": "Upstash",
  "homepage": "https://upstash.com"
}

README badge

README badge for upstash/skills/upstash-workflow-js