Join us for SpringOne, Jan 24-26, and learn how teams are building modern apps.
Live is streaming live. Watch now.

Job Scheduler

Why do you need this recipe?

To complete the need of running jobs/tasks on a particular schedule, using PCF tasks scheduler, this recipe outlines the steps to successfully provision a job.

Prerequisite

  1. The Scheduler for PCF is installed on the platform
  2. CF CLI plugin for Scheduler for PCF is installed. If not already, install scheduler-for-pcf-cliplugin-windows64-exe from https://network.pivotal.io/products/p-scheduler-for-pcf
    • cf install-plugin C\path\to\scheduler-for-pcf-cliplugin-windows64-exe
  3. A .NET/.NET Core headless/console app is available, which does the specific job. However, the example below uses a .NET console app

High level steps

  1. Create the app manifest file
  2. Deploy the application using the manifest
  3. Create a job
  4. Schedule a job

Create the app manifest file

To prevent the application from starting up immediately, set the instance count to zero in the manifest file. In addition, the buildpacks should be set to binary_buildpack. Lastly, ensure the command attribute is set. Take notice of the stack when setting the command. In the example below, the windows stack defaults to the classic batch command.

For example:

applications:
- name: ((appname))
  buildpacks:
  - binary_buildpack
  instances: 0
  health-check-type: process
  stack: windows
  command: cmd /c .\MyApp.exe
  path: bin/release

Deploy the application using the manifest

Execute cf push

For example:

cf push -f .\manifest.yml  --var appname=my-app

Create a job

Example, create a job called my-job from a cf app called my-app

cf create-job my-app my-job "MyApp"

Schedule a job

Example, schedule my-job to run every 5 minutes

`cf schedule-job my-job "*/5 * ? * * "`

Resources

  1. Schedule for PCF
  2. Cron Expression Generator
On This Page