> ## Documentation Index
> Fetch the complete documentation index at: https://vlyai-1c28d863.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Scheduled functions

> Run a Convex function at a future time — once after a delay, or on a recurring cron schedule.

Two ways to schedule:

## One-shot delayed

From any mutation or action:

```typescript theme={null}
await ctx.scheduler.runAfter(60 * 1000, api.foo.bar, { arg: "value" });
// runs once, 60 seconds from now
```

## Recurring (cron)

In `convex/crons.ts`:

```typescript theme={null}
import { cronJobs } from "convex/server";
import { api } from "./_generated/api";

const crons = cronJobs();

crons.cron(
  "nightly cleanup",
  "0 0 * * *",                    // standard cron, UTC
  api.maintenance.cleanup,
  {},
);

crons.interval(
  "every five minutes",
  { minutes: 5 },
  api.maintenance.poll,
  {},
);

export default crons;
```

## Common uses

<CardGroup cols={2}>
  <Card title="Reminder emails" icon="mail">
    Schedule from the booking creation mutation.
  </Card>

  <Card title="Nightly report" icon="chart-bar">
    Aggregate yesterday's data into a `dailyMetrics` table.
  </Card>

  <Card title="Cleanup" icon="trash">
    Delete soft-deleted rows after 30 days.
  </Card>

  <Card title="Renewal reminders" icon="repeat">
    "Mark subscription as renewing 24h before period end."
  </Card>
</CardGroup>

## Cancelling a scheduled run

```typescript theme={null}
const id = await ctx.scheduler.runAfter(...);
// later:
await ctx.scheduler.cancel(id);
```

## Related

<CardGroup cols={3}>
  <Card title="Background jobs" icon="cog" href="/features/data/background-jobs">
    Job-table pattern for longer work.
  </Card>

  <Card title="Inngest" icon="cog" href="/integrations/inngest">
    For complex multi-step workflows.
  </Card>

  <Card title="Actions" icon="zap" href="/convex/actions">
    What schedules typically call.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.