Skip to content

Commit

Permalink
Merge pull request #173 from Cognifide/bugfix/unknonw-status-of-scrip…
Browse files Browse the repository at this point in the history
…ts-execution

Fixed bug with unknown status of script's execution.
  • Loading branch information
mjedraszczyk authored Jun 17, 2019
2 parents d63f396 + b158b50 commit a9e9443
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.cache.CacheBuilder;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.osgi.service.component.ComponentContext;
Expand Down Expand Up @@ -59,10 +60,19 @@ public ExecutionSummary get(String id) {
}

@Getter
@RequiredArgsConstructor
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public static class ExecutionSummary implements Serializable {

private final boolean finished;
private final Progress progress;
private final String path;

public static ExecutionSummary running() {
return new ExecutionSummary(false, null, null);
}

public static ExecutionSummary finished(Progress progress, String path) {
return new ExecutionSummary(true, progress, path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public JobResult process(final Job job) {
try {
Progress progressLogger = scriptManager.process(script, mode, resolver);
String summaryPath = getSummaryPath(script, mode);
jobResultsCache.put(id, new ExecutionSummary(progressLogger, summaryPath));
jobResultsCache.put(id, ExecutionSummary.finished(progressLogger, summaryPath));
result = JobResult.OK;
} catch (RepositoryException | PersistenceException e) {
LOG.error("Script manager failed to process script", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.cognifide.cq.cqsm.core.servlets.BackgroundJobParameters;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -64,7 +65,9 @@ public Job scheduleJob(BackgroundJobParameters parameters) {
props.put(SCRIPT_PATH_PROPERTY_NAME, parameters.getSearchPath());
props.put(MODE_NAME_PROPERTY_NAME, parameters.getModeName());
props.put(USER_NAME_PROPERTY_NAME, parameters.getUserName());
return jobManager.addJob(JOB_SCRIPT_RUN_TOPIC, props);
Job job = jobManager.addJob(JOB_SCRIPT_RUN_TOPIC, props);
jobResultsCache.put(job.getId(), ExecutionSummary.running());
return job;

}

Expand All @@ -90,7 +93,11 @@ private JobProgressOutput getJobProgressIfFinished(Job job) {
private JobProgressOutput getJobProgress(String id) {
ExecutionSummary executionSummary = jobResultsCache.get(id);
if (executionSummary != null) {
return new JobProgressOutput(FINISHED, executionSummary.getPath(), executionSummary.getProgress().getEntries());
if (executionSummary.isFinished()) {
return new JobProgressOutput(FINISHED, executionSummary.getPath(), executionSummary.getProgress().getEntries());
} else {
return new JobProgressOutput(RUNNING);
}
}
return new JobProgressOutput(UNKNOWN);
}
Expand Down

0 comments on commit a9e9443

Please sign in to comment.