> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Jobs API

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/4/fusion-server/reference/api/jobs-api

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-server/reference/api/jobs-api

[old doc.lw link]: https://doc.lucidworks.com/fusion/5.9/327

The Jobs API allows you to define schedules for objects that perform work. You can schedule datasources, tasks, and Spark jobs.

This topic explains how to format requests to the Jobs API. To learn how to work with jobs and schedules in the Fusion UI, see [Jobs and Schedules](/docs/4/fusion-server/concepts/jobs/overview).

<LwTemplate />

## Job runtime configuration

<Note>
  In order to see this object within the [Fusion UI](/docs/4/fusion-server/concepts/object-explorer), it **must** be associated with an app. To do this, create the object using the `/apps` endpoint.
</Note>

Job configuration requests have these parameters:

* `<type>:<id>` path parameter (required)\
  The resource identifier takes the form `<type>:<id>`, such as `datasource:movie-db`, `spark:dailyMetricsRollup-counters`, or `task:delete-old-system-logs`.\
  See [Job types](#job-types) below.
* `enabled` body parameter\
  "True" or "false" to enable or disable the job.
* `triggers` body parameter\
  This parameter defines one or more conditions that trigger the job. See [Job triggers](#job-triggers) below.

Below is an example request that configures a job:

```sh wrap  theme={"dark"}
PUT /jobs/datasource:movie-db/schedule
{
  "enabled": true,
  "triggers": [
    {"type": "cron", "enabled": true, "value": "0 */10 * * * *"}
  ]
}
```

### Job types

The job type must be specified as part of the resource identifier in `PUT`, `POST`, and `DELETE` calls. These are the possible job types:

|              |                                                                                                                                                                                                                                                                                                                                                     |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `datasource` | A job to ingest data according to the specified datasource configuration, such as `datasource:movie-db`. Datasources are created using the [Connector Datasources API](/docs/4/fusion-server/reference/api/connector-apis/connector-datasources-api) or the Fusion UI.  See [Datasource Jobs](/docs/4/fusion-server/concepts/jobs/datasource-jobs). |
| `spark`      | A Spark job to process data, such as `spark:dailyMetricsRollup-counters`. Spark jobs are created using the [Spark Jobs API](/docs/4/fusion-server/reference/api/spark-jobs-api) or the Fusion UI.  See [Spark Jobs](/docs/4/fusion-server/concepts/jobs/spark-jobs).                                                                                |
| `task`       | A job to perform an HTTP call or log cleanup, such as `task:delete-old-system-logs`. Tasks are created using the [Tasks API](/docs/4/fusion-server/reference/api/tasks-api) or the Fusion UI.  See [Tasks](/docs/4/fusion-server/concepts/jobs/tasks).                                                                                              |

### Job triggers

Each job can have multiple triggers, and each trigger configuration requires `enabled` and `type` parameters.

Additional parameters are required by each trigger type, described below:

| Trigger type                                                       | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `interval` Run the job at a regular interval over some time range. | • `startTime` The date and time at which the job will first run, as an \[ISO-8601 date-time string([https://www.w3.org/TR/NOTE-datetime](https://www.w3.org/TR/NOTE-datetime)).<br />• `endTime` The date and time at which the job will run last, as an ISO-8601 date-time string.<br />• `interval` The interval at which the job will run, as an integer whose unit is specified by `repeatUnit` below.<br />• `repeatUnit` One of: `minute`, `hour`, or `day`. |
| `cron` Run the job on a cron-style schedule.                       | `value` A cron string.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `job` Run the job after another job succeeds or fails.             | • `jobID` The ID of the job that triggers this one.<br />• `runOnSuccess` "True" to run when the specified job succeeds.<br />• `runOnFailure` "True" to run when the specified job fails.<br />• `runOnAbort` "True" to run when the specified job is aborted.                                                                                                                                                                                                    |

## Examples

### Get all datasource jobs

**Input**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD https://FUSION_HOST:8764/api/jobs?type=datasource
```

**Output**

```json wrap  theme={"dark"}
[ {
  "resource" : "datasource:ratings-db",
  "enabled" : true,
  "startedBy" : "acb38917-611a-46e1-a3cf-4ed46a30fd24"
}, {
  "resource" : "datasource:movies-db",
  "enabled" : true,
  "startedBy" : "acb38917-611a-46e1-a3cf-4ed46a30fd24",
  "status" : "success",
  "lastStartTime" : "2017-05-17T20:58:10.503Z",
  "lastEndTime" : "2017-05-17T20:58:42.020Z"
} ]
```

### Start a datasource job now

**Input**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X POST -H "Content-Type: application/json" https://FUSION_HOST:8764/api/jobs/datasource:movies-db/actions -d '{"action": "start"}'
```

**Output**

```json wrap  theme={"dark"}
{
  "resource" : "datasource:movies-db",
  "action" : "start",
  "accepted" : true,
  "message" : "Started job datasource:movies-db"
}
```

### Get the job history for a datasource

**Input**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD https://FUSION_HOST:8764/api/jobs/datasource:movies-db/history
```

**Output**

```json wrap  theme={"dark"}
[ {
  "resource" : "datasource:movies-db",
  "startTime" : "2017-05-17T21:01:46.743Z",
  "endTime" : "2017-05-17T21:02:05.720Z",
  "status" : "success"
}, {
  "resource" : "datasource:movies-db",
  "startTime" : "2017-05-17T20:58:10.503Z",
  "endTime" : "2017-05-17T20:58:42.020Z",
  "status" : "success"
} ]
```

### Define a trigger for a datasource job

**Input**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X PUT -H "Content-Type: application/json" https://FUSION_HOST:8764/api/jobs/datasource:ratings-db/schedule -d '{"triggers": [{"type": "cron", "enabled": "true", "expression": "0 15 10 ? * MON-FRI"}]}'
```

**Output**

```json wrap  theme={"dark"}
{
  "resource" : "datasource:ratings-db",
  "triggers" : [ {
    "type" : "cron",
    "enabled" : true,
    "expression" : "0 15 10 ? * MON-FRI",
    "type" : "cron"
  } ]
}
```
