But sometimes there will be the scenario the scheduled job should be only executed in the master author node.
The below code snippet can be used to restrict the job getting executed only in the master author node.
@Reference
SlingRepository repository;
private void sampleScheduledJob() {
if(isRunMode("author") && isMasterRepository()){
//execute the job functionality here
}
}
private Boolean isRunMode(String mode) {
Set<String> runModes = slingSettings.getRunModes();
for (String runMode : runModes) {
if (runMode.equalsIgnoreCase(mode)) {
log.debug("Current Runmode is : " + runMode);
return true;
}
}
return false;
}
public boolean isMasterRepository(){
final String isMaster = repository.getDescriptor("crx.cluster.master");
log.debug("isMaster.."+isMaster);
return StringUtils.isNotBlank(isMaster) && Boolean.parseBoolean(isMaster);
}
No comments:
Post a Comment
If you have any doubts or questions, please let us know.