Skip to content

Commit

Permalink
Don't do jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
amarsan committed Nov 13, 2024
1 parent a37083e commit af59f70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 106 deletions.

This file was deleted.

This file was deleted.

70 changes: 12 additions & 58 deletions src/main/java/org/ohdsi/webapi/service/CDMResultsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.ohdsi.webapi.achilles.aspect.AchillesCache;
import org.ohdsi.webapi.achilles.service.AchillesCacheService;
import org.ohdsi.webapi.cdmresults.AchillesCacheTasklet;
import org.ohdsi.webapi.cdmresults.AchillesClearCacheTasklet;
import org.ohdsi.webapi.cdmresults.CDMResultsCacheTasklet;
import org.ohdsi.webapi.cdmresults.CDMResultsClearCacheTasklet;
import org.ohdsi.webapi.cdmresults.DescendantRecordAndPersonCount;
import org.ohdsi.webapi.cdmresults.DescendantRecordCount;
import org.ohdsi.webapi.cdmresults.domain.CDMCacheEntity;
Expand Down Expand Up @@ -48,6 +46,7 @@
import org.springframework.stereotype.Component;

import javax.ws.rs.Consumes;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -289,35 +288,17 @@ public JobExecutionResource refreshCache(@PathParam("sourceKey") final String so
* Clear the cdm_cache and achilles_cache for all sources
*
* @summary Clear the cdm_cache and achilles_cache for all sources
* @return List of JobExecutionResources
* @return void
* @throws ForbiddenException if the user is not an admin
*/
@GET
@Path("clearCache")
@Produces(MediaType.APPLICATION_JSON)
public List<JobExecutionResource> clearCache() {
List<JobExecutionResource> jobs = new ArrayList<>();

public void clearCache() {
if (!isSecured() || !isAdmin()) {
return jobs;
throw new ForbiddenException();
}

List<Source> sources = getSourceRepository().findAll();
for (Source source : sources) {
if (!sourceAccessor.hasAccess(source)) {
continue;
}
JobExecutionResource jobExecutionResource = jobService.findJobByName(Constants.CLEAR_CACHE,
getClearCacheJobName(String.valueOf(source.getSourceId()), source.getSourceKey()));
if (jobExecutionResource == null) {
if (source.getDaimons().stream()
.anyMatch(sd -> Objects.equals(sd.getDaimonType(), SourceDaimon.DaimonType.Results))) {
jobs.add(clearCache(source));
}
} else {
jobs.add(jobExecutionResource);
}
}
return jobs;
sources.parallelStream().forEach(this::clearCache);
}

/**
Expand Down Expand Up @@ -541,12 +522,12 @@ private void warmCaches(Collection<Source> sources) {
/*
* Clear cache for a single source
*/
private JobExecutionResource clearCache(Source source) {
String jobName = getClearCacheJobName(String.valueOf(source.getSourceId()), source.getSourceKey());
List<Step> jobSteps = createClearCacheJobSteps(source, jobName);
SimpleJobBuilder builder = createJob(jobName,
jobSteps);
return runJob(source.getSourceKey(), source.getSourceId(), jobName, builder);
private void clearCache(Source source) {
if (!sourceAccessor.hasAccess(source)) {
return;
}
cacheService.clearCache(source);
cdmCacheService.clearCache(source);
}

private SimpleJobBuilder createJob(String jobName, List<Step> steps) {
Expand Down Expand Up @@ -611,29 +592,6 @@ private Step getCountStep(Source source, String jobStepName) {
.build();
}

private List<Step> createClearCacheJobSteps(Source source, String jobName) {
SimpleJob job = new SimpleJob(jobName);
job.setJobRepository(jobRepository);
List<Step> steps = new ArrayList<>();
steps.add(getAchillesClearCacheStep(source, jobName));
steps.add(getCountClearCacheStep(source, jobName));
return steps;
}

private Step getAchillesClearCacheStep(Source source, String jobStepName) {
AchillesClearCacheTasklet achillesTasklet = new AchillesClearCacheTasklet(source, cacheService);
return stepBuilderFactory.get(jobStepName + " achilles")
.tasklet(achillesTasklet)
.build();
}

private Step getCountClearCacheStep(Source source, String jobStepName) {
CDMResultsClearCacheTasklet countTasklet = new CDMResultsClearCacheTasklet(source, cdmCacheService);
return stepBuilderFactory.get(jobStepName + " counts")
.tasklet(countTasklet)
.build();
}

private int getResultsDaimonPriority(Source source) {
Optional<Integer> resultsPriority = source.getDaimons().stream()
.filter(d -> d.getDaimonType().equals(SourceDaimon.DaimonType.Results))
Expand All @@ -647,10 +605,6 @@ private String getWarmCacheJobName(String sourceIds, String sourceKeys) {
return getJobName("warming cache", sourceIds, sourceKeys);
}

private String getClearCacheJobName(String sourceIds, String sourceKeys) {
return getJobName("clearing cache", sourceIds, sourceKeys);
}

private String getJobName(String jobType, String sourceIds, String sourceKeys) {
// for multiple sources: try to compose a job name from source keys, and if it is too long - use source ids
String jobName = String.format("%s: %s", jobType, sourceKeys);
Expand Down

0 comments on commit af59f70

Please sign in to comment.