Skip to content

Commit

Permalink
SAK-31479 Capture updates made while the SiteHierarchyJob runs (sakai…
Browse files Browse the repository at this point in the history
…project#3003)

* SAK-31479 Capture updates made while the SiteHierarchyJob runs

Previous handling of the last run date created a small window where
updates could be missed.

* SAK-31479 Replace "semaphore" boolean with DisallowConcurrentExecution annotation

Provides a more robust way of stopping the job running multiple
instances at once.
  • Loading branch information
marktriggs authored and ottenhoff committed Jul 27, 2016
1 parent 43e26d0 commit 09c8d8b
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.DisallowConcurrentExecution;
import org.sakaiproject.delegatedaccess.dao.DelegatedAccessDao;
import org.sakaiproject.delegatedaccess.logic.ProjectLogic;
import org.sakaiproject.delegatedaccess.logic.SakaiProxy;
Expand Down Expand Up @@ -65,6 +66,7 @@
* @author Bryan Holladay ([email protected])
*
*/
@DisallowConcurrentExecution
public class DelegatedAccessSiteHierarchyJob implements Job{

private static final Logger log = LoggerFactory.getLogger(DelegatedAccessSiteHierarchyJob.class);
Expand All @@ -76,24 +78,15 @@ public class DelegatedAccessSiteHierarchyJob implements Job{
private DelegatedAccessDao dao;
@Getter @Setter
private ProjectLogic projectLogic;

private static boolean semaphore = false;

public void init() {

}

public void execute(JobExecutionContext arg0) throws JobExecutionException {
//this will stop the job if there is already another instance running
if(semaphore){
log.warn("Stopping job since this job is already running");
return;
}
semaphore = true;

try{
log.info("DelegatedAccessSiteHierarchyJob started");
long startTime = System.currentTimeMillis();
Date startTime = new Date();

// newHiearchyNodeIds = new HashSet<String>();

Expand Down Expand Up @@ -210,20 +203,23 @@ public void execute(JobExecutionContext arg0) throws JobExecutionException {
log.warn(errors);
sakaiProxy.sendEmail("DelegatedAccessSiteHierarchyJob error", errors);
}else{
//no errors, so let's save this date so we can save time next run:
projectLogic.saveHierarchyJobLastRunDate(new Date(), rootNode.id);
//no errors, so let's save this date so we can save time next run.
//
//we use the time recorded when the job started
//to ensure that any modifications made while
//this job was running will be picked up by the
//next job run.
projectLogic.saveHierarchyJobLastRunDate(startTime, rootNode.id);
}

projectLogic.clearNodeCache();
//remove any sites that don't exist in the hierarchy (aka properties changed or site has been deleted):
// removeMissingNodes(rootNode);

log.info("DelegatedAccessSiteHierarchyJob finished in " + (System.currentTimeMillis() - startTime) + " ms and processed " + processedSites + " sites.");
log.info("DelegatedAccessSiteHierarchyJob finished in " + (System.currentTimeMillis() - startTime.getTime()) + " ms and processed " + processedSites + " sites.");
}catch (Exception e) {
log.error(e.getMessage(), e);
sakaiProxy.sendEmail("Error occurred in DelegatedAccessSiteHierarchyJob", e.getMessage());
}finally{
semaphore = false;
}
}

Expand Down

0 comments on commit 09c8d8b

Please sign in to comment.