Batch Job Scheduling

In the Batch Developers Guide, we showed you how to build batch applications and launch them in an ad-hoc fashion.
However, batch jobs are typically launched at scheduled times or based on events. In this section, we show you how you can schedule the launch of the batch jobs by using Spring Cloud Data Flow.

Spring Cloud Data Flow Scheduling Overview

Spring Cloud Data Flow lets you schedule the launching of tasks by setting a cron expression. You can create a schedule through the RESTful API or through the Spring Cloud Data Flow UI. Spring Cloud Data Flow schedules the execution of its tasks through a scheduling agent that is available on the cloud platform. Scheduling Architecture When using the Cloud Foundry platform, Spring Cloud Data Flow uses the PCF Scheduler. When using Kubernetes, cron jobs are used.

Scheduling a Batch Job

Make sure you have registered your timestamp application and created a definition for it as discussed in the Getting Started Guide. Using the UI, we schedule the timestamp-task by pressing the drop down button and selecting the "Schedule" option, as highlighted in the following image: Create Schedule

For this scenario, we want to launch this application once a minute. To do so, fill out the Schedule setup page as follows:

In the following sample, we set the name of the schedule to timestamp-task-once-a-minute and the cron expression to */1 * ? * *. Notice that the cron expression is expressed in the format used by Quartz. Also notice that we can add command line arguments and deployment parameters for this schedule, but we do not do so for this example. Once you have entered the cron expression, press the CREATE SCHEDULE(S) button. Now PCF Scheduler handles the scheduled launches for your batch application.

Schedule Batch App Cloud Foundry

In the following sample, we set the name of the schedule to timestamp-task-once-a-minute and the cron expression to */1 * * * *. Notice that we can add command line arguments and deployment parameters for this schedule, but we do not do so for this example. Now press the CREATE SCHEDULE(S) button. Now a Cron Job has been created to handle the scheduled launches for your batch application.

Schedule Batch App Kubernetes

Spring Cloud Data Flow does not offer an out-of-the-box solution for scheduling task launches on the local platform.
However, there are at least two Spring Boot native solutions that provide a scheduling option. You can implement them as custom solutions to make scheduling work in SCDF running locally.

Spring Boot Implementing a Quartz Scheduler

One option is to create a Spring Boot application that uses the Quartz scheduler to create RESTful API calls to launch tasks on Spring Cloud Data Flow. For more information, see here.

Spring Boot Implementing the @Scheduled annotation

Another option is to create a Spring Boot application that uses the @Scheduled annotation on a method that creates RESTful API calls to launch tasks on Spring Cloud Data Flow. You can read more informationabout it in the Spring Boot documentation.

When creating a task schedule, you can specify command line arguments and deployment properties for the scheduled application in the same way as you would specify them when launching a task. More can be read about specifying deployment properties in the Batch Feature Guide.

Monitoring Task Launches

You can view the status of each scheduled launch on Spring Cloud Data Flow's Tasks executions tab.

SCDF Scheduled Executions

Deleting a Schedule

From the Schedules tab, press the drop down button next to the schedule you want to remove and select the "Destroy" option, as the following image shows: Delete Schedule

When the confirmation dialog appears, press the DELETE THE SCHEDULE button. SCDF Confirm Schedule Delete