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

common-workflow-language / cwlviewer / #1997

13 May 2026 05:20PM UTC coverage: 70.25% (-0.08%) from 70.334%
#1997

Pull #751

github

kinow
Undo code deletion, but replace string concatenation by log+parameters
Pull Request #751: Bump org.springframework.boot:spring-boot-starter-parent from 3.1.4 to 4.1.0-RC1

119 of 196 new or added lines in 32 files covered. (60.71%)

20 existing lines in 4 files now uncovered.

1712 of 2437 relevant lines covered (70.25%)

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

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

90
    logger.info(
×
91
        queuedWorkflowRepository.deleteByTempRepresentation_RetrievedOnLessThanEqual(removeTime)
×
92
            + " Old queued workflows removed");
93
  }
×
94

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

117
  /**
118
   * For a given temporary directory, scans it (not recursively) for files and directories exceeding
119
   * the age limit threshold.
120
   *
121
   * @since 1.4.6
122
   * @see <a
123
   *     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>
124
   * @param temporaryDirectory temporary directory
125
   */
126
  private void clearDirectory(String temporaryDirectory) {
127
    final Instant cutoff = Instant.now().minus(Duration.ofDays(TMP_DIR_AGE_LIMIT_DAYS));
×
128

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

NEW
132
    if (files != null) {
×
133
      for (String fileName : files) {
×
134
        File fileToDelete = new File(temporaryDirectoryFile, fileName);
×
135
        try {
136
          FileUtils.forceDelete(fileToDelete);
×
137
        } catch (IOException e) {
×
138
          // Here we probably have a more serious case. Since the Git repository, RO directory, or
139
          // graphs are
140
          // not expected to be in use, and the application must have access, I/O errors are not
141
          // expected and
142
          // must be treated as errors.
143
          logger.error(
×
144
              String.format(
×
145
                  "Failed to delete old temporary file or directory [%s]: %s",
146
                  fileToDelete.getAbsolutePath(), e.getMessage()),
×
147
              e);
148
        }
×
149
      }
150
    }
151
  }
×
152
}
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