• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

common-workflow-language / cwlviewer / #1999

13 May 2026 10:23PM UTC coverage: 70.05% (-0.3%) from 70.334%
#1999

Pull #751

github

kinow
Last fixes to ease working with the SPARQL queries for a future PR, and more string concatenation removal
Pull Request #751: Bump org.springframework.boot:spring-boot-starter-parent from 3.1.4 to 4.1.0-RC1

120 of 208 new or added lines in 30 files covered. (57.69%)

21 existing lines in 5 files now uncovered.

1691 of 2414 relevant lines covered (70.05%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/commonwl/view/Scheduler.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.commonwl.view;
21

22
import java.io.File;
23
import java.io.IOException;
24
import java.time.Duration;
25
import java.time.Instant;
26
import java.util.Calendar;
27
import java.util.Date;
28
import java.util.List;
29
import java.util.stream.Stream;
30
import org.apache.commons.io.FileUtils;
31
import org.apache.commons.io.filefilter.AgeFileFilter;
32
import org.commonwl.view.workflow.QueuedWorkflowRepository;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.beans.factory.annotation.Value;
37
import org.springframework.scheduling.annotation.Scheduled;
38
import org.springframework.stereotype.Component;
39

40
/** Scheduler class for recurrent processes. */
41
@Component
42
public class Scheduler {
43

44
  private final Logger logger = LoggerFactory.getLogger(this.getClass());
×
45
  private final QueuedWorkflowRepository queuedWorkflowRepository;
46

47
  @Value("${queuedWorkflowAgeLimitHours}")
48
  private Integer QUEUED_WORKFLOW_AGE_LIMIT_HOURS;
49

50
  @Value("${tmpDirAgeLimitDays}")
51
  private Integer TMP_DIR_AGE_LIMIT_DAYS;
52

53
  // We do not want to remove the bundles, as we use the disk as a sort of
54
  // cache. Whenever a workflow page is displayed in the browser the UI
55
  // fires a request to re-generate it. We skip that by keeping files on disk.
56
  @Value("${graphvizStorage}")
57
  private String graphvizStorage;
58

59
  @Value("${gitStorage}")
60
  private String gitStorage;
61

62
  @Autowired
63
  public Scheduler(QueuedWorkflowRepository queuedWorkflowRepository) {
×
64
    this.queuedWorkflowRepository = queuedWorkflowRepository;
×
65
  }
×
66

67
  /**
68
   * A Scheduled function to delete old queued workflow entries from the queue. Age is determined by
69
   * QUEUED_WORKFLOW_AGE_LIMIT_HOURS
70
   */
71
  @Scheduled(cron = "${cron.deleteOldQueuedWorkflows}")
72
  public void removeOldQueuedWorkflowEntries() {
73
    Calendar calendar = Calendar.getInstance();
×
74
    Date now = new Date();
×
75
    calendar.setTime(now);
×
76

77
    if (QUEUED_WORKFLOW_AGE_LIMIT_HOURS == null) {
×
78
      QUEUED_WORKFLOW_AGE_LIMIT_HOURS = 24;
×
79
    }
80

81
    // calculate time QUEUED_WORKFLOW_AGE_LIMIT_HOURS before now
82
    calendar.add(Calendar.HOUR, -QUEUED_WORKFLOW_AGE_LIMIT_HOURS);
×
83
    Date removeTime = calendar.getTime();
×
84

NEW
85
    logger.info("The time is {}", now);
×
NEW
86
    logger.info("Delete time interval is : OLDER THAN {} HOURS", QUEUED_WORKFLOW_AGE_LIMIT_HOURS);
×
NEW
87
    logger.info("Deleting queued workflows older than or equal to {}", removeTime);
×
88

89
    logger.info(
×
90
        "{} Old queued workflows removed",
NEW
91
        queuedWorkflowRepository.deleteByTempRepresentation_RetrievedOnLessThanEqual(removeTime));
×
UNCOV
92
  }
×
93

94
  /**
95
   * Scheduled function to delete old temporary directories.
96
   *
97
   * <p>Will scan each temporary directory (graphviz, RO, git), searching for files exceeding a
98
   * specified threshold.
99
   *
100
   * <p>It scans the first level directories, i.e. it does not recursively scan directories. So it
101
   * will delete any RO or Git repository directories that exceed the threshold. Similarly, it will
102
   * delete any graph (svg, png, etc.) that also exceeds it.
103
   *
104
   * <p>Errors logged through Logger. Settings in Spring application properties file.
105
   *
106
   * @since 1.4.6
107
   */
108
  @Scheduled(cron = "${cron.clearTmpDir}")
109
  public void clearTmpDir() {
110
    // Temporary files used for graphviz, RO, and git may be stored in different
111
    // locations, so we will collect all of them here.
112
    List<String> temporaryDirectories = Stream.of(graphvizStorage, gitStorage).distinct().toList();
×
113
    temporaryDirectories.forEach(this::clearDirectory);
×
114
  }
×
115

116
  /**
117
   * For a given temporary directory, scans it (not recursively) for files and directories exceeding
118
   * the age limit threshold.
119
   *
120
   * @since 1.4.6
121
   * @see <a
122
   *     href="https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/AgeFileFilter.html">https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/AgeFileFilter.html</a>
123
   * @param temporaryDirectory temporary directory
124
   */
125
  private void clearDirectory(String temporaryDirectory) {
126
    final Instant cutoff = Instant.now().minus(Duration.ofDays(TMP_DIR_AGE_LIMIT_DAYS));
×
127

128
    File temporaryDirectoryFile = new File(temporaryDirectory);
×
129
    String[] files = temporaryDirectoryFile.list(new AgeFileFilter(Date.from(cutoff)));
×
130

NEW
131
    if (files != null) {
×
132
      for (String fileName : files) {
×
133
        File fileToDelete = new File(temporaryDirectoryFile, fileName);
×
134
        try {
135
          FileUtils.forceDelete(fileToDelete);
×
136
        } catch (IOException e) {
×
137
          // Here we probably have a more serious case. Since the Git repository, RO directory, or
138
          // graphs are
139
          // not expected to be in use, and the application must have access, I/O errors are not
140
          // expected and
141
          // must be treated as errors.
142
          logger.error(
×
143
              "Failed to delete old temporary file or directory [{}]: {}",
NEW
144
              fileToDelete.getAbsolutePath(),
×
NEW
145
              e.getMessage(),
×
146
              e);
147
        }
×
148
      }
149
    }
150
  }
×
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc