001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sys.batch.service;
017    
018    import java.util.Date;
019    import java.util.List;
020    
021    import org.kuali.kfs.sys.batch.BatchJobStatus;
022    import org.kuali.kfs.sys.batch.Job;
023    import org.quartz.JobDetail;
024    import org.quartz.JobExecutionContext;
025    import org.quartz.Scheduler;
026    
027    public interface SchedulerService {
028        public static final String PENDING_JOB_STATUS_CODE = "Pending";
029        public static final String SCHEDULED_JOB_STATUS_CODE = "Scheduled";
030        public static final String RUNNING_JOB_STATUS_CODE = "Running";
031        public static final String SUCCEEDED_JOB_STATUS_CODE = "Succeeded";
032        public static final String FAILED_JOB_STATUS_CODE = "Failed";
033        public static final String CANCELLED_JOB_STATUS_CODE = "Cancelled";
034    
035        public static final String SCHEDULED_GROUP = "scheduled";
036        public static final String UNSCHEDULED_GROUP = "unscheduled";
037    
038        public void initialize();
039    
040        public void initializeJob(String jobName, Job job);
041    
042        /**
043         * This method checks whether any jobs in the SCHEDULED job group are pending or currently scheduled.
044         * 
045         * @return hasIncompleteJob
046         */
047        public boolean hasIncompleteJob();
048    
049        /**
050         * This method should be used to determine when the daily batch schedule should terminate. It compares the start time of the
051         * schedule job from quartz with a time specified by the scheduleStep_CUTOFF_TIME system parameter in the SYSTEM security group
052         * on the day after the schedule job started running.
053         * 
054         * @return pastScheduleCutoffTime
055         */
056        public boolean isPastScheduleCutoffTime();
057    
058        public void processWaitingJobs();
059    
060        public void logScheduleResults();
061    
062        public boolean shouldNotRun(JobDetail jobDetail);
063    
064        public String getStatus(JobDetail jobDetail);
065    
066        public void updateStatus(JobDetail jobDetail, String jobStatus);
067    
068        public void setScheduler(Scheduler scheduler);
069    
070        public List<BatchJobStatus> getJobs(String groupName);
071    
072        /**
073         * Get all jobs known to the scheduler wrapped within a BusinessObject-derived class.
074         * 
075         * @return
076         */
077        public List<BatchJobStatus> getJobs();
078    
079        /**
080         * Gets a single job based on its name and group.
081         * 
082         * @param groupName
083         * @param jobName
084         * @return
085         */
086        public BatchJobStatus getJob(String groupName, String jobName);
087    
088        /**
089         * Immediately runs the specified job.
090         * 
091         * @param jobName
092         * @param startStep
093         * @param stopStep
094         * @param requestorEmailAddress
095         */
096        public void runJob(String jobName, int startStep, int stopStep, Date startTime, String requestorEmailAddress);
097    
098        /**
099         * Immediately runs the specified job.
100         * 
101         * @param jobName
102         * @param requestorEmailAddress
103         */
104        public void runJob(String jobName, String requestorEmailAddress);
105    
106        /**
107         * Returns the list of job currently running within the scheduler.
108         * 
109         * @return
110         */
111        public List<JobExecutionContext> getRunningJobs();
112    
113        /**
114         * Removes a job from the scheduled group.
115         * 
116         * @param jobName
117         */
118        public void removeScheduled(String jobName);
119    
120        /**
121         * Adds the given job to the "scheduled" group.
122         * 
123         * @param job
124         */
125        public void addScheduled(JobDetail job);
126    
127        /**
128         * Adds the given job to the "unscheduled" group.
129         * 
130         * @param job
131         */
132        public void addUnscheduled(JobDetail job);
133    
134        /**
135         * Returns a list of all groups defined in the scheduler.
136         * 
137         * @return
138         */
139        public List<String> getSchedulerGroups();
140    
141        /**
142         * Returns a list of all possible statuses.
143         * 
144         * @return
145         */
146        public List<String> getJobStatuses();
147    
148        /**
149         * Requests that the given job be stopped as soon as possble. It is up to the job to watch for this request and terminiate. Long
150         * running steps may not end unless they check for the interrupted status on their current Thread ot Step instance.
151         * 
152         * @param jobName
153         */
154        public void interruptJob(String jobName);
155    
156        /**
157         * Tests whether the referenced job name is running, regardless of group.
158         * 
159         * @param jobName
160         * @return
161         */
162        public boolean isJobRunning(String jobName);
163    
164        /**
165         * Returns the next start time for the given job.
166         * 
167         * @param job
168         * @return
169         */
170        public Date getNextStartTime(BatchJobStatus job);
171    
172        /**
173         * Returns the next start time for the given job.
174         * 
175         * @param groupName
176         * @param jobName
177         * @return
178         */
179        public Date getNextStartTime(String groupName, String jobName);
180        
181        public void reinitializeScheduledJobs();
182    }