forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-31479 Capture updates made while the SiteHierarchyJob runs (sakai…
…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
1 parent
43e26d0
commit 09c8d8b
Showing
1 changed file
with
11 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -65,6 +66,7 @@ | |
* @author Bryan Holladay ([email protected]) | ||
* | ||
*/ | ||
@DisallowConcurrentExecution | ||
public class DelegatedAccessSiteHierarchyJob implements Job{ | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DelegatedAccessSiteHierarchyJob.class); | ||
|
@@ -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>(); | ||
|
||
|
@@ -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; | ||
} | ||
} | ||
|
||
|