Skip to content

Commit 36fb17f

Browse files
author
Mark Robinson
committed
Bug fixes for URL and cache logic
1 parent dc79173 commit 36fb17f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/main/java/org/commonwl/viewer/services/WorkflowService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ public boolean cacheExpired(Workflow workflow) {
131131
logger.debug("Current: " + workflow.getLastCommit() + ", HEAD: " + currentHead);
132132

133133
// Reset date in database if there are still no changes
134-
boolean changes = workflow.getLastCommit().equals(currentHead);
135-
if (changes) {
134+
boolean expired = !workflow.getLastCommit().equals(currentHead);
135+
if (!expired) {
136136
workflow.setRetrievedOn(new Date());
137137
workflowRepository.save(workflow);
138138
}
139139

140140
// Return whether the cache has expired
141-
return !changes;
141+
return expired;
142142
} else {
143143
// Cache expiry time has not elapsed yet
144144
return false;

src/main/java/org/commonwl/viewer/web/WorkflowController.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,20 @@ public ModelAndView getWorkflowByGithubDetails(@PathVariable("owner") String own
159159
if (workflowModel != null) {
160160
boolean cacheExpired = workflowService.cacheExpired(workflowModel);
161161
if (cacheExpired) {
162-
workflowService.removeWorkflow(workflowModel);
163-
workflowModel = null;
162+
// Update by trying to add a new workflow
163+
Workflow newWorkflow = workflowService.newWorkflowFromGithub(workflowModel.getRetrievedFrom());
164+
165+
// Only replace workflow if it could be successfully parsed
166+
if (newWorkflow == null) {
167+
logger.error("Could not parse updated workflow " + workflowModel.id);
168+
} else {
169+
// Delete the existing workflow
170+
workflowService.removeWorkflow(workflowModel);
171+
172+
// Save new workflow
173+
workflowRepository.save(newWorkflow);
174+
workflowModel = newWorkflow;
175+
}
164176
}
165177
}
166178

src/main/resources/templates/workflow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ <h4 class="modal-title" id="dotGraphLabel">Workflow DOT Graph</h4>
9898

9999
<div class="container">
100100
<div class="row">
101-
<div class="col-md-12" role="main" id="main" th:with="workflowURL=@{'github.com/' + ${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/tree/' + ${workflow.retrievedFrom.lastCommit} + '/' + ${workflow.retrievedFrom.path}}">
101+
<div class="col-md-12" role="main" id="main" th:with="workflowURL=@{'github.com/' + ${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/tree/' + ${workflow.lastCommit} + '/' + ${workflow.retrievedFrom.path}}">
102102
<h2>Workflow: <span th:text="${workflow.label}">Workflow Name</span></h2>
103103
<p>
104104
<a th:href="@{'https://' + ${workflowURL}}" href="#" rel="noopener" target="_blank">

0 commit comments

Comments
 (0)