> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/components/async/schedule.md).

# Schedule

Manages scheduled tasks in the BoxLang scheduler.

## Component Signature

```
<bx:schedule action=[string]
task=[string]
scheduler=[string]
group=[string]
URL=[string]
class=[string]
method=[string]
interval=[string]
isDaily=[boolean]
cronTime=[string]
startDate=[string]
startTime=[string]
endDate=[string]
endTime=[string]
repeat=[integer]
exclude=[string]
port=[integer]
username=[string]
password=[string]
proxyServer=[string]
proxyPort=[integer]
proxyUser=[string]
proxyPassword=[string]
publish=[boolean]
path=[string]
file=[string]
overwrite=[boolean]
resolveUrl=[boolean]
retryCount=[integer]
onException=[string]
onComplete=[string]
eventhandler=[string]
cluster=[boolean]
result=[string] />
```

### Attributes

| Atrribute       | Type      | Required | Description                                                                                                                                       | Default      |
| --------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| `action`        | `string`  | `true`   |                                                                                                                                                   |              |
| `task`          | `string`  | `false`  |                                                                                                                                                   |              |
| `scheduler`     | `string`  | `false`  |                                                                                                                                                   | `bxschedule` |
| `group`         | `string`  | `false`  |                                                                                                                                                   |              |
| `URL`           | `string`  | `false`  |                                                                                                                                                   |              |
| `class`         | `string`  | `false`  |                                                                                                                                                   |              |
| `method`        | `string`  | `false`  |                                                                                                                                                   | `run`        |
| `interval`      | `string`  | `false`  |                                                                                                                                                   |              |
| `isDaily`       | `boolean` | `false`  |                                                                                                                                                   | `false`      |
| `cronTime`      | `string`  | `false`  |                                                                                                                                                   |              |
| `startDate`     | `string`  | `false`  |                                                                                                                                                   |              |
| `startTime`     | `string`  | `false`  |                                                                                                                                                   |              |
| `endDate`       | `string`  | `false`  |                                                                                                                                                   |              |
| `endTime`       | `string`  | `false`  |                                                                                                                                                   |              |
| `repeat`        | `integer` | `false`  |                                                                                                                                                   |              |
| `exclude`       | `string`  | `false`  |                                                                                                                                                   |              |
| `port`          | `integer` | `false`  | Optional HTTP port override for the URL. When omitted, the URL's own scheme determines the default port (e.g. `443` for `https`, `80` for `http`) |              |
| `username`      | `string`  | `false`  |                                                                                                                                                   |              |
| `password`      | `string`  | `false`  |                                                                                                                                                   |              |
| `proxyServer`   | `string`  | `false`  |                                                                                                                                                   |              |
| `proxyPort`     | `integer` | `false`  |                                                                                                                                                   |              |
| `proxyUser`     | `string`  | `false`  |                                                                                                                                                   |              |
| `proxyPassword` | `string`  | `false`  |                                                                                                                                                   |              |
| `publish`       | `boolean` | `false`  |                                                                                                                                                   | `false`      |
| `path`          | `string`  | `false`  |                                                                                                                                                   |              |
| `file`          | `string`  | `false`  |                                                                                                                                                   |              |
| `overwrite`     | `boolean` | `false`  |                                                                                                                                                   | `true`       |
| `resolveUrl`    | `boolean` | `false`  |                                                                                                                                                   | `false`      |
| `retryCount`    | `integer` | `false`  |                                                                                                                                                   | `3`          |
| `onException`   | `string`  | `false`  |                                                                                                                                                   | `refire`     |
| `onComplete`    | `string`  | `false`  |                                                                                                                                                   |              |
| `eventhandler`  | `string`  | `false`  |                                                                                                                                                   |              |
| `cluster`       | `boolean` | `false`  |                                                                                                                                                   | `false`      |
| `result`        | `string`  | `false`  |                                                                                                                                                   |              |

## Examples

### Create a scheduled task

Creates a new task that fires an HTTP GET request against a URL on a recurring interval.

```java
<bx:schedule
    action="create"
    task="dailyReport"
    url="https://example.com/tasks/daily-report.bx"
    interval="daily"
    startTime="08:00"
>

```

### Create a task that runs a BoxLang class

Instead of firing an HTTP request, point a task at a BoxLang class with `class` (mutually exclusive with `url`). The class is instantiated once and reused for the life of the task, and its `run()` method (or the method named by `method`) is invoked on every fire:

```java
<bx:schedule
    action="create"
    task="dailyReport"
    class="tasks.DailyReport"
    interval="daily"
    startTime="08:00"
>

```

```java
// tasks/DailyReport.bx
class {

    function run() {
        // do the work
    }

}
```

The class may optionally define any of `before()`, `after(result)`, `onSuccess(result)`, and `onError(exception)` — each is only invoked if defined, following the same convention as a BoxLang scheduler class's life-cycle methods:

```java
// tasks/DailyReport.bx
class {

    function before() {
        logger.info( "About to generate the daily report" );
    }

    function run() {
        // do the work and (optionally) return a result
        return generateReport();
    }

    function onSuccess( result ) {
        logger.info( "Daily report generated: #result#" );
    }

    function onError( exception ) {
        logger.error( "Daily report failed: #exception.message#" );
    }

    function after( result ) {
        logger.info( "Daily report task finished" );
    }

}
```

A custom method name can be used instead of `run()`:

```java
<bx:schedule
    action="create"
    task="cleanup"
    class="tasks.Cleanup"
    method="purgeOldFiles"
    interval="daily"
>

```

### Create a task with cron expression

```java
<bx:schedule
    action="create"
    task="cleanup"
    url="/tasks/cleanup.bx"
    cronTime="0 0 2 * * ?"
>

```

### Create a task that runs every 5 minutes

```java
<bx:schedule
    action="create"
    task="healthCheck"
    url="/tasks/health.bx"
    interval="300"
>

```

### Update an existing task

```java
<bx:schedule
    action="update"
    task="dailyReport"
    url="/tasks/daily-report-v2.bx"
    interval="daily"
    startTime="09:00"
>

```

### Run a task immediately

```java
<bx:schedule
    action="run"
    task="dailyReport"
>

```

### Pause and resume a task

```java
<bx:schedule action="pause" task="dailyReport">
<bx:schedule action="resume" task="dailyReport">

```

### List all scheduled tasks

```java
<bx:schedule action="list" result="tasks">
<bx:dump var="#tasks#">

```

### List tasks filtered by group

```java
<bx:schedule action="list" group="reports" result="reportTasks">

```

### Pause or resume all tasks

```java
<bx:schedule action="pauseall">
<bx:schedule action="resumeall">

```

### Delete a scheduled task

```java
<bx:schedule action="delete" task="oldTask">

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/components/async/schedule.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
