# Scheduling Tasks

Spring Cloud Data Flow 允许用户通过 `cron表达式`安排 Task 的执行。可以通过 RESTful API 或 Spring Cloud Data Flow UI 创建计划。

## 1. 调度程序

Spring Cloud Data Flow 将通过云平台上提供的调度代理安排 Task 的执行。使用Cloud Foundry平台时，Spring Cloud Data Flow将使用 [PCF Scheduler](https://www.cloudfoundry.org/the-foundry/scheduler/)。当使用 Kubernetes ，将使用 [cronjob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)。

![调度程序架构概述](https://raw.githubusercontent.com/spring-cloud/spring-cloud-dataflow/master/spring-cloud-dataflow-docs/src/main/asciidoc/images/dataflow-scheduling-architecture.png)

## 2. 启用计划

默认情况下，Spring Cloud Data Flow 会禁用调度功能。要启用计划功能，必须将以下属性设置为`true`：

* `spring.cloud.dataflow.features.schedules-enabled`
* `spring.cloud.dataflow.features.tasks-enabled`

## 3. Schedule的生命周期

schedule 的生命周期有两部分：

* [Scheduling a Task Execution](https://docs.spring.io/spring-cloud-dataflow/docs/2.1.0.RELEASE/reference/htmlsingle/#spring-cloud-data-flow-schedule-scheduling)
* [Deleting a Schedule](https://docs.spring.io/spring-cloud-dataflow/docs/2.1.0.RELEASE/reference/htmlsingle/#spring-cloud-data-flow-schedule-unscheduling)

### **3.1. 安排 Task 执行**

您可以通过以下方式安排 Task执行：

* RESTful API
* Spring Cloud Data Flow Dashboard

要从 UI 安排，请单击屏幕顶部的`Tasks`选项卡，这将转到 Task Definitions 页面。然后，从要安排的Task Definitions中，单击与要安排的任务定义关联的 clock 图标。这将引导您进入一个`Create Schedule(s)`页面，为计划创建唯一名称并关联的cron表达式。您可以为单个 Task Definitions 创建多个计划。

### **3.2. 删除计划**

您可以通过以下方式删除计划：

* RESTful API
* Spring Cloud Data Flow Dashboard

{% hint style="warning" %}
删除计划，并不会停止当前正在运行的任务。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cxz.gitbook.io/spring-cloud-date-flow/tasks/scheduling-tasks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
