Run cron jobs in a Cloud Foundry app.
JavaScript Shell
Latest commit 8232814 Mar 9, 2016 @afeld afeld Merge pull request #11 from brittag/license
Adding standard 18F contributing and license files
Permalink
Failed to load latest commit information.
jobs/cf-quota-perm-set reformat recurring job Jul 3, 2015
CONTRIBUTING.md
LICENSE.md Adding standard 18F contributing and license files Mar 9, 2016
README.md
cf-cron.js
count3.sh updated readme and example for multiple jobs Jul 9, 2015
crontab.json updated readme and example for multiple jobs Jul 9, 2015
crontab.yml
manifest.yml example manifest Jul 8, 2015
package.json handles multiple cronjobs and one optional prep job per cronjob Jul 8, 2015

README.md

cf-cron

Run cron jobs in a Cloud Foundry app.

Usage:

This app expects a bound service holding credentials and a crontab.yml or crontab.json with the following format:

crontab.yml

---
jobs:
  - name: job-1
    schedule: "0 * * * * *"
    command: "/bin/bash, job.sh, creds.key"
    tz: "America/Los_Angeles"
    prep:
      name: job-1-prep
      command: "/bin/bash, prep.sh, creds.username, creds.password"
  - name: job-2
    schedule: "0 * * * * *"
    command: "/bin/bash, job2.sh, creds.key"
Job Parameters:
  • prep:
    Description: An optional job which runs once, prior to the recurring job. Takes an array-formatted command with optional parameters. Specify a script here to avoid unexpected issues with variable expansion.

    Example: "/bin/bash, prep.sh"

  • command:
    Description: The recurring job. An array-formatted command with optional parameters. Specify a script here to avoid unexpected issues with variable expansion.
    Example: "/bin/bash, job.sh, creds.username, creds.password"

    Parameters passed to PREP_JOB and CRON_JOB with the creds. prefix will eval to variables held in the service specified by CF_CREDS.

  • schedule:
    Description: A cron schedule. For more information see: Cron Ranges. This parameter only applies to cronjobs, prep jobs run immediately.
    Example: "0 * * * * *"

  • tz: [optional]
    Description: Time Zone for the cronjob.
    Example: "America/Los_Angeles"

Credential Service:

This app will take advantage of secrets held in the credentials of either a bound service or a user-provided service. To store arbitrary credentials or non-public variables, use the syntax below to set up a user-provided service.

cf cups cf-cron-creds -p '{"username":"user", "password":"password"}'

Running the Example:

Create the credential service.

cf cups cf-cron-creds -p '{"username":"user", "password":"password"}'

Push the app.

cf push

The app will:

  1. Start the first prep job which counts to 3.
  2. Start the second cronjob which echoes betelgeuse every 3 seconds.
  3. When the first prep completes, start the first cronjob which echoes sirius every 5 seconds.

Output:

Found crontab.yml.
cf-cron started...
Found 2 jobs.
0:job-1
1:job-2
Preparing for: job-1 with job-1-prep
Creating Job: job-2
Prep: job-1-prep - Out: Count 1/3 
Prep: job-1-prep - Out: Count 2/3 
Job: job-2 - Out: betelgeuse
Job: job-2 - Exit: 0
Prep: job-1-prep - Out: Count 3/3 
Prep: job-1-prep - Exit: 0
Finished: job-1-prep
Creating Job: job-1
Job: job-2 - Out: betelgeuse
Job: job-2 - Exit: 0
Job: job-1 - Out: sirius
Job: job-1 - Exit: 0