Schedules

Docs

Schedules run an HTTP destination on a cron expression and keep delivery records. This demo creates one managed schedule against /api/hello, waits for the first recorded delivery, then deletes it. Use schedules for recurring jobs such as syncs, cleanup, reports, and polling external systems.

Schedules demo is ready.
Ready
Creates a schedule that calls /api/hello once a minute and shows the first recorded delivery.
Reference Code
import { ScheduleClient } from "@agentuity/schedule";

const schedules = new ScheduleClient();
const name = "nightly-sync-" + crypto.randomUUID();
const appUrl = process.env.APP_URL ?? "https://your-app.agentuity.dev";
let scheduleId: string | undefined;
let destinationId: string | undefined;
let summary: {
  scheduleId: string;
  destinationCount: number;
  listed: boolean;
  deliveries: number;
  expression: string;
};

try {
  const { schedule, destinations } = await schedules.create({
    name,
    description: "Call the sync endpoint every night",
    expression: "0 2 * * *",
    destinations: [{
      type: "url",
      config: {
        url: appUrl + "/api/sync",
        method: "POST",
      },
    }],
  });

  scheduleId = schedule.id;

  const extraDestination = await schedules.createDestination(schedule.id, {
    type: "url",
    config: {
      url: appUrl + "/api/audit-sync",
      method: "POST",
    },
  });
  destinationId = extraDestination.destination.id;

  const fetched = await schedules.get(schedule.id);
  const page = await schedules.list({ limit: 25 });
  const deliveryHistory = await schedules.listDeliveries(schedule.id, {
    limit: 10,
  });
  // update() takes partial fields (name, description, expression); changing
  // the expression recomputes the next run time.
  const updated = await schedules.update(schedule.id, {
    expression: "0 3 * * *",
  });

  summary = {
    scheduleId: fetched.schedule.id,
    destinationCount: fetched.destinations.length,
    listed: page.schedules.some((item) => item.id === schedule.id),
    deliveries: deliveryHistory.deliveries.length,
    expression: updated.schedule.expression,
  };
} finally {
  if (destinationId) await schedules.deleteDestination(destinationId);
  if (scheduleId) await schedules.delete(scheduleId);
}

export { summary };
Ready
Output will appear here...