Implementing Scheduler

This section shows the microservices in which you can implement the Scheduler feature and also it shows you the implementation steps.

You can implement the Scheduler feature in the following microservices:

Configuration

Schedulers are uniquely identified by the ID (that is operation ID) associated with it. In order to implement scheduler in a microservice, you must implement the SchedulerFunctionInterface interface in the business implementation class and add the business logic in invoke method by overriding.

The method signature of invoke method is as follows:

SchedulerCommandOutput invoke (Context context, SchedulerCommandInput input)

Where,

  • Context – Scheduler context
  • SchedulerCommandInput – Input payload containing operation Id and additional parameters for scheduler execution that can be passed at runtime.
  • SchedulerCommandOutput – Output payload containing attributes for response body such as status, message, response object, etc.
NOTE: Implementation of business logic is common for all environments and does not vary with deployment environment.

Configuring Scheduler in Docker

Procedure

  1. Add the scheduler.json file containing the operationId (mandatory) and parameters under <ms-project>-core/src/main/resources/scheduler/. See a sample scheduler.json for reference.
  1. Add .package-project-scheduler-enabled under <ms-project>-package\<ms-project>-package-docker/ for creating ${artifact-id}-scheduler.jar.
  1. Make sure dockerfile is available under <ms-project>-package/<ms- project> -package-docker/src/docker/app/ms-framework-scheduler/Dockerfile.
  1. Make sure the following properties are set in the config/ENV.env file.
  2. SCHEDULER_CONTEXT=app/ms-framework-scheduler/.
    scheduler_artifactid=${artifact-id}-scheduler.jar
    SCHEDULER_IMAGE=temenos/${artifact-id}-scheduler
    SCHEDULER_BASE_IMAGE=openjdk:8-jre-alpine
  3. Define a container for scheduler in docker-compose.yml that is ${artifact-id}.yml.
  1. Make sure the scheduler container has the following environment variables.
  2. className_<operationId>: <fully qualified class name of class containing the scheduler business logic> → operationId to implementation class mapping 
    temn.msf.scheduler.<operationId>.cron.trigger.time: <CRON expression> → ​CRON trigger time mapping
    class.inbox.dao: com.temenos.microservice.framework.core.inbox.InboxDaoImpl → property for inbox
    class.outbox.dao: com.temenos.microservice.framework.core.outbox.OutboxDaoImpl → property for outbox

Configuring Scheduler in AWS

Procedure

  1. Create a lambda function for scheduler using the install scripts.
  2. Create a cloud watch rule using CRON expressions.
  3. Add permissions for the new lambda function and configure the cloud watch rule to trigger scheduler lambda function.

Configuring Scheduler in Azure

Procedure

  1. Make sure to add .package-project-scheduler-enabled under <ms-project>-package/<ms-project>-package-azure/, so that the scheduler folder gets created with appropriate function.json file inside target/azure-functions/<functionapp>/ after the build.
  2. In install scripts, make sure to add the following scheduler specific properties.
  3. className_<operationId>=<fully qualified class name>
    schedulerTime=%SCHEDULER_TIME_CRON_EXPRESSION% 
    operationId=<operationId>
    parameters=<payload in JSON format>
    NOTE: Since the schedulers in MSF are configured and identified based on the environment variable operationId, a single Azure function app cannot have more than one scheduler. Hence, additonal Azure function apps has to be created to accommodate additional scheduler functions.

Bookmark Name Actions
Feedback
x