How to execute the Quartz scheduler job only in master author node - AEM/Adobe CQ5
While we are deploying the scheduler in Adobe Experience Manager(AEM), the scheduler will be active in master/slave author nodes and all the publish nodes(based on our deployment configuration).
But sometimes there will be scenario the scheduled job should
be only executed in master author node.
The below code snippet can be used to restrict the job
getting executed only in 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