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

openmrs / openmrs-core / 23193642646

17 Mar 2026 12:13PM UTC coverage: 63.1% (-0.3%) from 63.429%
23193642646

push

github

rkorytkowski
Fixing: Fix an issue with the ModuleResourceServlet

0 of 2 new or added lines in 1 file covered. (0.0%)

925 existing lines in 17 files now uncovered.

23137 of 36667 relevant lines covered (63.1%)

0.63 hits per line

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

78.95
/api/src/main/java/org/openmrs/scheduler/SchedulerUtil.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.scheduler;
11

12
import java.util.Calendar;
13
import java.util.Date;
14

15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
/**
19
 * @deprecated since 2.9.x used only for legacy tasks
20
 */
21
@Deprecated
22
public class SchedulerUtil {
23
        
24
        private SchedulerUtil() {
25
        }
26
        
27
        private static final Logger log = LoggerFactory.getLogger(SchedulerUtil.class);
1✔
28
        
29
        /**
30
         * Gets the next execution time based on the initial start time (possibly years ago, depending
31
         * on when the task was configured in OpenMRS) and the repeat interval of execution. We need to
32
         * calculate the "next execution time" because the scheduled time is most likely in the past and
33
         * the JDK timer will run the task X number of times from the start time until now in order to
34
         * catch up. The assumption is that this is not the desired behavior -- we just want to execute
35
         * the task on its next execution time. For instance, say we had a scheduled task that ran every
36
         * 24 hours at midnight. In the database, the task would likely have a past start date (e.g.
37
         * 04/01/2006 12:00am). If we scheduled the task using the JDK Timer
38
         * scheduleAtFixedRate(TimerTask task, Date startDate, int interval) method and passed in the
39
         * start date above, the JDK Timer would execute this task once for every day between the start
40
         * date and today, which would lead to hundreds of unnecessary (and likely expensive)
41
         * executions.
42
         * 
43
         * @see java.util.Timer
44
         * @param taskDefinition the task definition to be executed
45
         * @return the next "future" execution time for the given task
46
         * <strong>Should</strong> get the correct repeat interval
47
         * 
48
         * @deprecated since 2.9.x used only for legacy tasks
49
         */
50
        @Deprecated
51
        public static Date getNextExecution(TaskDefinition taskDefinition) {
52
                Calendar nextTime = Calendar.getInstance();
1✔
53
                
54
                try {
55
                        Date firstTime = taskDefinition.getStartTime();
1✔
56
                        
57
                        if (firstTime != null) {
1✔
58
                                
59
                                // Right now
60
                                Date currentTime = new Date();
1✔
61
                                
62
                                // If the first time is actually in the future, then we use that date/time
63
                                if (firstTime.after(currentTime)) {
1✔
UNCOV
64
                                        return firstTime;
×
65
                                }
66
                                
67
                                // The time between successive runs (e.g. 24 hours)
68
                                long repeatInterval = taskDefinition.getRepeatInterval();
1✔
69
                                if (repeatInterval == 0) {
1✔
70
                                        // task is one-shot so just return the start time
UNCOV
71
                                        return firstTime;
×
72
                                }
73
                                
74
                                // Calculate time between the first time the process was run and right now (e.g. 3 days, 15 hours)
75
                                long betweenTime = currentTime.getTime() - firstTime.getTime();
1✔
76
                                
77
                                // Calculate the last time the task was run   (e.g. 15 hours ago)
78
                                long lastTime = (betweenTime % (repeatInterval * 1000));
1✔
79
                                
80
                                // Calculate the time to add to the current time (e.g. 24 hours - 15 hours = 9 hours)
81
                                long additional = ((repeatInterval * 1000) - lastTime);
1✔
82
                                
83
                                nextTime.setTime(new Date(currentTime.getTime() + additional));
1✔
84
                                
85
                                log.debug("The task " + taskDefinition.getName() + " will start at " + nextTime.getTime());
1✔
86
                        }
87
                }
88
                catch (Exception e) {
×
89
                        log.error("Failed to get next execution time for " + taskDefinition.getName(), e);
×
90
                }
1✔
91
                
92
                return nextTime.getTime();
1✔
93
        }
94
        
95
}
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