|
1 |
| -package org.commonwl.view.workflow; |
| 1 | +package org.commonwl.view; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import org.commonwl.view.workflow.QueuedWorkflowRepository; |
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
4 | 7 | import org.springframework.beans.factory.annotation.Autowired;
|
| 8 | +import org.springframework.beans.factory.annotation.Value; |
5 | 9 | import org.springframework.scheduling.annotation.Scheduled;
|
6 | 10 | import org.springframework.stereotype.Component;
|
7 | 11 |
|
| 12 | +import java.util.Calendar; |
8 | 13 | import java.util.Date;
|
9 | 14 |
|
| 15 | +/** |
| 16 | + * Scheduler class for recurrent processes. |
| 17 | + */ |
10 | 18 | @Component
|
11 | 19 | public class Scheduler {
|
12 | 20 |
|
| 21 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
13 | 22 | private final QueuedWorkflowRepository queuedWorkflowRepository;
|
14 | 23 |
|
| 24 | + @Value("${queuedWorkflowAgeLimitHours}") |
| 25 | + private Integer QUEUED_WORKFLOW_AGE_LIMIT_HOURS; |
| 26 | + |
15 | 27 | @Autowired
|
16 | 28 | public Scheduler(QueuedWorkflowRepository queuedWorkflowRepository) {
|
17 | 29 | this.queuedWorkflowRepository = queuedWorkflowRepository;
|
18 | 30 | }
|
19 | 31 |
|
20 |
| - @Scheduled(cron = "* * * * * ?") |
| 32 | + |
| 33 | + /** |
| 34 | + * A Scheduled function to delete old queued workflow entries |
| 35 | + * from the queue. Age is determined by DELETE_INTERVAL_HOUR |
| 36 | + */ |
| 37 | + @Scheduled(cron = "${cron.deleteOldQueuedWorkflows}") |
21 | 38 | public void removeOldQueuedWorkflowEntries() {
|
| 39 | + Calendar calendar = Calendar.getInstance(); |
22 | 40 | Date now = new Date();
|
23 |
| - System.out.println("The time is " + now); |
24 |
| - System.out.println("The repository is " + queuedWorkflowRepository.toString()); |
| 41 | + calendar.setTime(now); |
| 42 | + |
| 43 | + if (QUEUED_WORKFLOW_AGE_LIMIT_HOURS == null) { |
| 44 | + QUEUED_WORKFLOW_AGE_LIMIT_HOURS = 24; |
| 45 | + } |
| 46 | + |
| 47 | + // calculate time QUEUED_WORKFLOW_AGE_LIMIT_HOURS before now |
| 48 | + calendar.add(Calendar.HOUR, -QUEUED_WORKFLOW_AGE_LIMIT_HOURS); |
| 49 | + Date removeTime = calendar.getTime(); |
| 50 | + |
| 51 | + logger.info("The time is " + now); |
| 52 | + logger.info("Delete time interval is : OLDER THAN " + QUEUED_WORKFLOW_AGE_LIMIT_HOURS + " HOURS"); |
| 53 | + logger.info("Deleting queued workflows older than or equal to " + removeTime); |
| 54 | + |
| 55 | + logger.info(queuedWorkflowRepository.deleteByTempRepresentation_RetrievedOnLessThanEqual(removeTime) |
| 56 | + + " Old queued workflows removed"); |
25 | 57 | }
|
26 | 58 | }
|
0 commit comments