package org.commonwl.view.workflow;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class Scheduler {

    private final QueuedWorkflowRepository queuedWorkflowRepository;

    @Autowired
    public Scheduler(QueuedWorkflowRepository queuedWorkflowRepository) {
        this.queuedWorkflowRepository = queuedWorkflowRepository;
    }

    @Scheduled(cron = "* * * * * ?")
    public void removeOldQueuedWorkflowEntries() {
        Date now = new Date();
        System.out.println("The time is " + now);
        System.out.println("The repository is " + queuedWorkflowRepository.toString());
    }
}

@@ -22,20 +22,128 @@
 view
-.workflow;%0A%0A
+;%0A%0A%0Aimport org.commonwl.view.workflow.QueuedWorkflowRepository;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0Aimp
@@ -198,24 +198,83 @@
 .Autowired;%0A
+import org.springframework.beans.factory.annotation.Value;%0A
 import org.s
@@ -392,119 +392,373 @@
 til.
-Date;%0A%0A@Component%0Apublic class Scheduler %7B%0A%0A    private final QueuedWorkflowRepository queuedWorkflowRepository
+Calendar;%0Aimport java.util.Date;%0A%0A/**%0A * Scheduler class for recurrent processes.%0A */%0A@Component%0Apublic class Scheduler %7B%0A%0A    private final Logger logger = LoggerFactory.getLogger(this.getClass());%0A    private final QueuedWorkflowRepository queuedWorkflowRepository;%0A%0A    @Value(%22$%7BqueuedWorkflowAgeLimitHours%7D%22)%0A    private Integer QUEUED_WORKFLOW_AGE_LIMIT_HOURS
 ;%0A%0A 
@@ -922,262 +922,1079 @@
  %7D%0A%0A
+%0A
     
-@Scheduled(cron = %22* * * * * ?%22)%0A    public void removeOldQueuedWorkflowEntries() %7B%0A        Date now = new Date();%0A        System.out.println(%22The time is %22 + now);%0A        System.out.println(%22The repository is %22 + queuedWorkflowRepository.toString()
+/**%0A     * A Scheduled function to delete old queued workflow entries%0A     * from the queue. Age is determined by DELETE_INTERVAL_HOUR%0A     */%0A    @Scheduled(cron = %22$%7Bcron.deleteOldQueuedWorkflows%7D%22)%0A    public void removeOldQueuedWorkflowEntries() %7B%0A        Calendar calendar = Calendar.getInstance();%0A        Date now = new Date();%0A        calendar.setTime(now);%0A%0A        if (QUEUED_WORKFLOW_AGE_LIMIT_HOURS == null) %7B%0A            QUEUED_WORKFLOW_AGE_LIMIT_HOURS = 24;%0A        %7D%0A%0A        // calculate time QUEUED_WORKFLOW_AGE_LIMIT_HOURS before now%0A        calendar.add(Calendar.HOUR, -QUEUED_WORKFLOW_AGE_LIMIT_HOURS);%0A        Date removeTime = calendar.getTime();%0A%0A        logger.info(%22The time is %22 + now);%0A        logger.info(%22Delete time interval is : OLDER THAN %22 + QUEUED_WORKFLOW_AGE_LIMIT_HOURS + %22 HOURS%22);%0A        logger.info(%22Deleting queued workflows older than or equal to %22 + removeTime);%0A%0A        logger.info(queuedWorkflowRepository.deleteByTempRepresentation_RetrievedOnLessThanEqual(removeTime)%0A                + %22 Old queued workflows removed%22
 );%0A 

Implement Scheduler component for cron jobs