Task-Scheduler

Page last updated:

Overview

The Task-Scheduler is a marketplace service that allows you to schedule and automatically run tasks for your applications. You can use it to schedule periodical execution of any tasks on the Application Cloud, including database migrations, emails, batch jobs, etc..

Usage

Create Service Instance

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

$ cf create-service task-scheduler free my-scheduler
Creating service instance my-scheduler in org my-org / space my-space as user@example.ch...
OK

$ cf services
Getting services in org my-org / space my-space as user@example.ch...

name                         service          plan    bound apps                          last operation       broker                upgrade available
my-scheduler                 task-scheduler   free                                        create succeeded     task-scheduler

Bind Service Instance

For an app to use the service, you must first bind it to the service instance.

To bind an app to a Task-Scheduler instance, run cf bind-service APP-NAME SERVICE-INSTANCE-NAME -c '{"schedule":"CRONTAB-SCHEDULE", "task":"COMMAND-TO-EXECUTE"}', replacing APP-NAME with the name of the app you want to use the scheduling service for, SERVICE-INSTANCE-NAME with the service instance name, CRONTAB-SCHEDULE with a valid cron schedule entry (see for https://en.wikipedia.org/wiki/Cron) and COMMAND-TO-EXECUTE with the task command you want to execute on your app.

Nonstandard schedule keywords like @daily or @weekly are not supported!

$ cf bind-service my-app my-scheduler -c '{"schedule":"0 2 * * *", "task":"rake cleanup-database"}'

Binding service my-scheduler to my-app in org my-org / space my-space as user@example.ch...
OK

TIP: Use 'cf push' to ensure your env variable changes take effect

After binding a Task-Scheduler instance to your app, the configured task will be executed automatically according to the provided cron schedule.

It is also possible to overwrite the memory and/or disk limits of a task during binding:

$ cf bind-service my-app my-scheduler -c '{"schedule":"0 2 * * *", "task":"rake cleanup-database", "memory_in_mb":128, "disk_in_mb":512}'

Binding service my-scheduler to my-app in org my-org / space my-space as user@example.ch...
OK

View Tasks

To view running and finished tasks, run cf tasks.

$ cf tasks my-app
Getting tasks for app my-app in org my-org / space my-space as user@example.ch...
OK

id  name                                   state       start time                      command
3   2f458b3f-c383-4422-866f-31bd7fda9ac3   SUCCEEDED   Thu, 29 Aug 2019 02:00:05 UTC   rake cleanup-database
2   2f458b3f-c383-4422-866f-31bd7fda9ac3   SUCCEEDED   Wed, 28 Aug 2019 02:00:19 UTC   rake cleanup-database
1   2f458b3f-c383-4422-866f-31bd7fda9ac3   SUCCEEDED   Tue, 27 Aug 2019 02:00:03 UTC   rake cleanup-database
View the source for this page in GitHub