0

I want to design a scheduler as service using spring-boot. My scheduler should be generic so that other microservices can use it as they want.

I tried normal spring boot examples.

/** * This scheduler will run on every 20 Seconds. */ @Scheduled(fixedRate = 20 * 1000, initialDelay = 5000) public void scheduleTaskWithInitialDelay() { logger.info("Fixed Rate Task With Initail Delay 20 Seconds:: Execution Time - "+dateTimeFormatter.format(LocalDateTime.now())); }

/**
 * This scheduler will run on every 10 Seconds.
 */
@Scheduled(fixedRate = 10* 1000, initialDelay = 5000)
public void scheduleTaskWithInitialDelay1() {
    logger.info("Fixed Rate Task With Initail Delay 10 Seconds:: Execution Time - "+dateTimeFormatter.format(LocalDateTime.now()));
}
2
  • What do you mean by "My scheduler should be generic so that other microservices can use it as they want"?
    – Chris
    Commented Sep 19, 2019 at 6:04
  • @Anil if you have to call using rest api, you have crate controller for that..means you have to create rest api for that... Commented Sep 19, 2019 at 6:07

1 Answer 1

1

You need to store other microservice's requests to schedule something in your persistent. So, you have an inventory that which microservice requested the scheduling service and with delay or cron or something else.

Now, you can read all the requested configuration from the database and start scheduler for them.

This is a common use case in enterprise applications when people choose to write custom code.

Your database table should contain all the detail + what to do if scheduler reached to given time (Push data/event to some URL or something else).

Some technical detail

You schedule service should allow to

  • Add Schedule
  • Start/Stop/Update existing schedule
  • Callback or some other operation when scheduler meet the time

Hope, this will help.

Not the answer you're looking for? Browse other questions tagged or ask your own question.