Reputation: 1
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()));
}
Upvotes: 0
Views: 1711
Reputation: 4870
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
Hope, this will help.
Upvotes: 1