I am trying to find a way to run a method at a specific time set by different users, let me explain!
Let's suppose we have 2 sites: siteA and siteB and those sites have admins: adminA and adminB respectively.
Each admin can create a work schedule in which the rabbitmq queues in his site are launched.
Right now, each admin launch his queues manually.
What i want is, lets say for exemple:
adminA created a work schedule from 08:00 to 18:00
adminB created a work schedule from 09:00 to 17:30
I want the method that launches a site queues to be executed at the time specified by the admin of that site so :
queueA1, queueA2, queueA3... launched at 08:00
queueB1, queueB2... launched at 09:30
lets suppose the method called launchQueues(String siteId)
I have learned about @Scheduled but it seems like it is only applicable when i want to call a method in a fixed time
CodePudding user response:
You can have a common job which is scheduled to run every n minutes. This job can find any queue that need to be launched at that time interval and then launch it.
e.g. This job is scheduled for every 5 mins.
At 9:00 am, findQueuesToLaunch() method will find the queues that need to be launched at 9:00 am and not already running.
@Scheduled(cron = "0 0/5 * * * ?") public void launchQueue() {
List<String> queues = findQueuesToLaunch();
for (String queueId in queues) {
launchQueue(queueId);
}
}