Skip to main content
You can schedule a workflow to run periodically using a cron definition. For this feature, you would need to use Upstash QStash’s Schedules feature.

Scheduling a workflow

For example, let’s suppose that you have a workflow that creates a backup of some important data daily. Our workflow endpoint might look like this: To run this endpoint on a schedule, navigate to Schedules in your QStash dashboard and click Create Schedule:
Enter your live endpoint URL, add a CRON expression to define the interval at which your endpoint is called (i.e. every day, every 15 minutes, …) and click Schedule:
Your workflow will now run repeatedly at the interval you have defined. For more details on CRON expressions, see our QStash scheduling documentation.

Programmatically Schedule

In order to massively improve the user experience, many applications send weekly summary reports to their users. These could be weekly analytics summaries or SEO statistics to keep users engaged with the platform. Let’s create a user-specific schedule, sending a first report to each user exactly 7 days after they signed up:
import { signUp } from "@/utils/auth-utils";
import { Client } from "@upstash/qstash";

const client = new Client({ token: process.env.QSTASH_TOKEN! });

export async function POST(request: Request) {
  const userData: UserData = await request.json();

  // Schedule weekly account summary
  await client.schedules.create({
    scheduleId: `user-summary-${user.email}`,
    destination: "https://<YOUR_APP_URL>/api/send-weekly-summary",
    body: { userId: user.id },
    cron: cron,
  });

  return NextResponse.json(
    { success: true, message: "User registered and summary scheduled" },
    { status: 201 }
  );
}
This code will call our workflow every week, starting exactly seven days after a user signs up. Each call to our workflow will contain the respective user’s ID.
When creating a per-user schedule, pass a unique scheduleId to identify the schedule for better management and observability.