Using Scheduler for PCF

IMPORTANT: The Scheduler for Pivotal Cloud Foundry (PCF) tile is currently in beta and is intended for evaluation and test purposes only. Do not use this product in a PCF production environment.

This topic provides instructions for using Scheduler for Pivotal Cloud Foundry (PCF). The service enables ad hoc and scheduled execution of PCF tasks.

You can interact with the service through the Cloud Foundry Command Line Interface (cf CLI) tool or the Apps Manager UI.

For general information, see Managing Service Instances with the cf CLI.

Prerequisites

  • A PCF installation with Scheduler for PCF installed and listed in the Marketplace
  • A Space Developer account
  • (Optional) If you want to use the Scheduler for PCF CLI Plugin, you must install it on your local machine. This plugin is packaged with the tile on Pivotal Network.

Create and Bind a Service Instance

Every app and service in PCF is scoped to a space. This means that an app can use a service only if an instance of the service exists in the same space.

The Scheduler for PCF service is a singleton service. Only one service instance can be created in a space.

Confirm Service Availability

For apps to use a service, the service must be available in the Marketplace. To confirm you have installed Scheduler for PCF:

  1. Run cf marketplace from the command line.
  2. If the output lists scheduler-for-pcf in the service column, Scheduler for PCF is available. If the service is not available, install it.

    $ cf marketplace
    Getting services from marketplace in org my-org / space my-space as user@example.com...
    OK
    service             plans      description
    [...]
    scheduler-for-pcf   standard   Scheduler service
    [...]
    

Create a Service Instance

To create an instance of the Scheduler for PCF service, run cf create-service scheduler-for-pcf standard SERVICE-INSTANCE-NAME, replacing SERVICE-INSTANCE-NAME with a name of your choice. After you create the service instance, this name appears under service in the output of the cf services command.

See the following example:

$ cf create-service scheduler-for-pcf standard my-instance
Creating service my-instance in org my-org / space my-space as user@example.com... OK
$ cf services
Getting services in org my-org / space my-space as user@example.com... OK name service plan bound apps last operation my-instance scheduler-for-pcf standard create succeeded

You can create only one instance in a space. If you attempt to create more than one instance in a space, you receive an error response.

Bind a Service Instance to Your App

For an app to use a service, you must bind it to a service instance. Do this after you push or re-push the app using cf push.

To bind an app to a Scheduler instance, run cf bind-service APP-NAME SERVICE-INSTANCE-NAME, replacing APP-NAME with the name of the app you want to use the Scheduler service for and SERVICE-INSTANCE-NAME with the name you provided when you ran cf create-service.

$ cf bind-service my-app my-instance
Binding service my-instance to my-app in org my-org / space my-space as user@example.com... OK TIP: Use 'cf push' to ensure your env variable changes take effect

Manage Jobs

See the following sections to learn about the operations you can perform with Scheduler for PCF.

Create a New Job

To execute tasks related to an app, create a new job by running cf create-job APP-NAME JOB-NAME COMMAND:

  • APP-NAME is the app you want to execute a task against.
  • JOB-NAME is the name for your job.
  • COMMAND is the command you wish to execute.

See the following example:

 $ cf create-job my-app my-job "pwd"
Creating job my-job for my-app with command pwd in org my-org / space my-space as user@example.com... Job Name App Name Command my-job my-app pwd OK

List Jobs

Use the cf CLI to list all jobs in a space by running cf jobs. See the following example:

$ cf jobs
Listing jobs for org my-org / space my-space as user@example.com... Job Name App Name Command my-job my-app pwd OK

Execute a Job

You can execute a job manually. This is often useful to test the proper configuration of a job prior to scheduling it for recurring execution.

Run cf run-job JOB-NAME. See the following example:

$ cf run-job my-job
Enqueuing job my-job for app my-app in org my-org / space my-space as user@example.com... OK

View Job History

You can review job history by running cf job-history JOB-NAME:

$ cf job-history my-job
Getting scheduled job history for my-job in org my-org / space my-space as user@example.com... 1 - 1 of 1 Total Results Execution GUID Execution State Scheduled Time Execution Start Time Execution End Time Exit Message 8a7e808a5b883a25015b89b4a12c0001 SUCCEEDED Mon, 10 Apr 2017 13:00:00 UTC Mon, 10 Apr 2017 13:00:00 UTC Mon, 10 Apr 2017 13:00:01 UTC 202 - Cloud Controller Accepted Task

View Logs

You can view logs for jobs by running cf logs JOB-NAME --recent.

Note: Scheduler jobs are executed as CF Tasks.

See the following example:

$ cf logs my-job --recent
Connected, dumping recent logs for app my-app in org my-org / space my-space as user@example.com... [...] 2017-04-19T23:04:13.79-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT Creating container 2017-04-19T23:04:14.01-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT Successfully created container 2017-04-19T23:04:14.22-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT bin 2017-04-19T23:04:14.22-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT db 2017-04-19T23:04:14.23-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT Exit status 0 2017-04-19T23:04:14.24-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT Destroying container 2017-04-19T23:04:14.55-0600 [APP/TASK/cc6fab7f-32a9-4404-4574-b0c430a96cd9 -|- 0d30f4f0-11a4-4d6a-7e77-5e1cdc1aa5ec/0]OUT Successfully destroyed container [...]

Schedule a Job

You can schedule a job to execute at any time using a schedule expression. Scheduler for PCF requires cron expressions in the MIN HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK format.

For example, to execute a job at noon every day, run the following command:

$ cf schedule-job my-job "0 12 * * * "

A single job can have multiple schedules. Each schedule has a GUID to help distinguish it from similar schedules.

View Schedules for Jobs

You can review schedules for all jobs in a space by running cf job-schedules. See the following example:

$ cf job-schedules my-job "0 12 * * *"
Getting scheduled jobs for org my-org / space my-space as user@example.com... App Name: my-app my-job pwd 2b69e0c2-9664-46bb-4817-54afcedbb65d 0 12 * * * OK

Delete a Job Schedule

You can delete a specific schedule by running cf delete-job-schedule SCHEDULE_GUID, where SCHEDULE_GUID is the GUID found in the output of the job-schedules command. See the following example:

$ cf delete-job-schedule 2b69e0c2-9664-46bb-4817-54afcedbb65d
Really delete the schedule 2b69e0c2-9664-46bb-4817-54afcedbb65d / 0 12 * * * and all associated history?> [yN]: y OK

Delete a Job

You can delete a job by running cf delete-job JOB_NAME. See the following example:

$ cf delete-job my-job
Really delete the job my-job with command pwd and all associated schedules and history?> [yN]:y OK
Create a pull request or raise an issue on the source for this page in GitHub