You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/12/26 22:32:09 UTC

cvs commit: jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule JobEntry.java JobQueue.java TurbineSchedulerService.java

jmcnally    01/12/26 13:32:09

  Modified:    src/services/java/org/apache/fulcrum/schedule JobEntry.java
                        JobQueue.java TurbineSchedulerService.java
  Log:
  When loading jobs from the cold storrage the
  initial time is not calculated and there for the calls to getNextRuntime all
  return 0, which results in an immediate execution of the job. This is not
  desiareble for daily, weekly or monthly jobs.
  
  the sorting of the jobQueue was not
  based on runtime but on the jobID which also results in very strange
  results.
  
  patches by Erik Kazandjian
  
  Revision  Changes    Path
  1.4       +11 -10    jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/JobEntry.java
  
  Index: JobEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/JobEntry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JobEntry.java	2001/09/20 22:57:55	1.3
  +++ JobEntry.java	2001/12/26 21:32:09	1.4
  @@ -64,7 +64,7 @@
    * Unix scheduler cron.
    *
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: JobEntry.java,v 1.3 2001/09/20 22:57:55 jon Exp $
  + * @version $Id: JobEntry.java,v 1.4 2001/12/26 21:32:09 jmcnally Exp $
    */
   public class JobEntry
       extends org.apache.fulcrum.schedule.BaseJobEntry
  @@ -224,24 +224,25 @@
       {
           Calendar schedrun = Calendar.getInstance();
           Calendar now = Calendar.getInstance();
  -
  + 
           switch( evaluateJobType() )
           {
  -        case 0:
  +        case SECOND:
               // SECOND (every so many seconds...)
               schedrun.add(Calendar.SECOND, getSecond());
               runtime = schedrun.getTime().getTime();
               break;
  -        case 1:
  +
  +        case MINUTE:
               // MINUTE (every so many minutes...)
               schedrun.add(Calendar.SECOND, getSecond());
               schedrun.add(Calendar.MINUTE, getMinute());
               runtime = schedrun.getTime().getTime();
               break;
   
  -        case 2:
  +        case WEEK_DAY:
               // WEEKDAY (day of the week)
  -            schedrun.add(Calendar.SECOND, getSecond());
  +            schedrun.set(Calendar.SECOND, getSecond());
               schedrun.set(Calendar.MINUTE, getMinute());
               schedrun.set(Calendar.HOUR_OF_DAY, getHour());
               schedrun.set(Calendar.DAY_OF_WEEK, getWeekDay());
  @@ -259,9 +260,9 @@
               }
               break;
   
  -        case 3:
  +        case DAY_OF_MONTH:
               // DAY_OF_MONTH (date of the month)
  -            schedrun.add(Calendar.SECOND, getSecond());
  +            schedrun.set(Calendar.SECOND, getSecond());
               schedrun.set(Calendar.MINUTE, getMinute());
               schedrun.set(Calendar.HOUR_OF_DAY, getHour());
               schedrun.set(Calendar.DAY_OF_MONTH, getDayOfMonth());
  @@ -279,9 +280,9 @@
               }
               break;
   
  -        case 4:
  +        case DAILY:
               // DAILY (certain hour:minutes of the day)
  -            schedrun.add(Calendar.SECOND, getSecond());
  +            schedrun.set(Calendar.SECOND, getSecond());
               schedrun.set(Calendar.MINUTE, getMinute());
               schedrun.set(Calendar.HOUR_OF_DAY, getHour());
   
  
  
  
  1.3       +13 -2     jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/JobQueue.java
  
  Index: JobQueue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/JobQueue.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JobQueue.java	2001/08/10 11:46:24	1.2
  +++ JobQueue.java	2001/12/26 21:32:09	1.3
  @@ -57,12 +57,13 @@
   import java.util.List;
   import java.util.Vector;
   import java.util.Collections;
  +import java.util.Comparator;
   
   /**
    * Queue for the scheduler.
    *
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: JobQueue.java,v 1.2 2001/08/10 11:46:24 knielsen Exp $
  + * @version $Id: JobQueue.java,v 1.3 2001/12/26 21:32:09 jmcnally Exp $
    */
   public class JobQueue
   {
  @@ -209,6 +210,16 @@
        */
       private void sortQueue()
       {
  -        Collections.sort(queue);
  +        Comparator aComparator = new Comparator () 
  +            {
  +                public int compare(Object o1, Object o2) 
  +                {
  +                    Long time1 = new Long (((JobEntry)o1).getNextRuntime());
  +                    Long time2 = new Long (((JobEntry)o2).getNextRuntime());
  +                    return (time1.compareTo(time2));
  +                }
  +            };
  +                                               
  +        Collections.sort(queue,aComparator);
       }
   }
  
  
  
  1.3       +12 -2     jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/TurbineSchedulerService.java
  
  Index: TurbineSchedulerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/TurbineSchedulerService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TurbineSchedulerService.java	2001/08/02 05:31:12	1.2
  +++ TurbineSchedulerService.java	2001/12/26 21:32:09	1.3
  @@ -56,6 +56,7 @@
   
   import java.util.List;
   import java.util.Vector;
  +import java.util.Iterator;
   import org.apache.fulcrum.BaseService;
   import org.apache.fulcrum.InitializationException;
   import org.apache.torque.om.NumberKey;
  @@ -65,7 +66,7 @@
    * Service for a cron like scheduler.
    *
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: TurbineSchedulerService.java,v 1.2 2001/08/02 05:31:12 jvanzyl Exp $
  + * @version $Id: TurbineSchedulerService.java,v 1.3 2001/12/26 21:32:09 jmcnally Exp $
    */
   public class TurbineSchedulerService
       extends BaseService
  @@ -117,6 +118,11 @@
   
               if ( jobs != null && jobs.size() > 0 )
               {
  +                Iterator it = jobs.iterator();
  +                while(it.hasNext())
  +                {
  +                    ((JobEntry)it.next()).calcRunTime();
  +                }
                   scheduleQueue.batchLoad(jobs);
                   restart();
               }
  @@ -158,7 +164,8 @@
       }
   
       /**
  -     * Add a new job to the queue.
  +     * Add a new job to the queue.  Before adding a job, calculate the runtime 
  +     * to make sure the entry will be placed at the right order in the queue.
        *
        * @param je A JobEntry with the job to add.
        * @exception Exception, a generic exception.
  @@ -168,6 +175,9 @@
       {
           try
           {
  +            // Calculate the runtime to make sure the entry will be placed 
  +            // at the right order
  +            je.calcRunTime();
               // Save to DB.
               je.save();
           }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>