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;
017
018 import java.util.Date;
019
020 import org.apache.log4j.Logger;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.kfs.sys.batch.service.SchedulerService;
023
024 public class ScheduleStep extends AbstractStep {
025 private static final Logger LOG = Logger.getLogger(ScheduleStep.class);
026 private SchedulerService schedulerService;
027
028 /**
029 * @see org.kuali.kfs.sys.batch.Step#execute(String, Date)
030 */
031 public boolean execute(String jobName, Date jobRunDate) {
032 boolean isPastScheduleCutoffTime = false;
033 schedulerService.reinitializeScheduledJobs();
034 while (schedulerService.hasIncompleteJob() && !isPastScheduleCutoffTime) {
035 schedulerService.processWaitingJobs();
036 isPastScheduleCutoffTime = schedulerService.isPastScheduleCutoffTime();
037 try {
038 Thread.sleep(Integer.parseInt(getParameterService().getParameterValue(getClass(), KFSConstants.SystemGroupParameterNames.BATCH_SCHEDULE_STATUS_CHECK_INTERVAL)));
039 }
040 catch (InterruptedException e) {
041 throw new RuntimeException("Schedule step encountered interrupt exception while trying to wait for the specified batch schedule status check interval", e);
042 }
043 }
044 if (isPastScheduleCutoffTime) {
045 LOG.info("Schedule exceeded cutoff time, so it was terminated before completion");
046 }
047 schedulerService.logScheduleResults();
048 return !isPastScheduleCutoffTime;
049 }
050
051 /**
052 * Sets the schedulerService attribute value.
053 *
054 * @param schedulerService The schedulerService to set.
055 */
056 public void setSchedulerService(SchedulerService schedulerService) {
057 this.schedulerService = schedulerService;
058 }
059 }