Job Scheduler with CAP Application

In this example, we will create a service binding with the Job Scheduler service and configure it to trigger an endpoint in the CAP application.

To achieve this, we will follow these steps-

  • Create Service Binding on CAP application
  • Authorize Job Scheduler Service Instance

Step 1 - Create Service Binding on CAP application

We can declare the Job Scheduler Service requirement under modules requires section in mta.yaml file like-

mta.yaml
- name: cap-application-job-scheduler

We can then define the Job Scheduler Service resource details under resources section like-

mta.yaml
# Declare Job Scheduler Resources below
- name: cap-application-job-scheduler
  type: org.cloudfoundry.managed-service
  parameters:
    service: jobscheduler
    service-plan: standard
    service-name: cap-application-job-scheduler-instance  # <-- Job Schedular Instance name
    config:
      enable-job-scheduler: true

Step 2 - Authorize Job Scheduler Service Instance

We can then define the authorization for the Job Scheduler in xs-security.json file like-

xs-security.json
{
  "scopes": [
    {
      "name": "$XSAPPNAME.JobScheduler",
      "description": "Job Scheduler Scope",
      "grant-as-authority-to-apps": [
        "$XSSERVICENAME(cap-application-job-scheduler-instance)"
      ]
    }
  ],
  "attributes": [],
  "role-templates": [
    {
      "name": "JobSchedulerRole",
      "description": "Role collection for Job Scheduler calls",
      "scope-references": [
        "$XSAPPNAME.JobScheduler"
      ]
    }
  ]
}

You can now configure the Job and Schedules on the Job Scheduler instance.

!!! Its Done !!!