src/dird/scheduler.c
static void find_runs()
{
   time_t now, next_hour, runtime;
   RUN *run;
   JOB *job;
   SCHED *sched;
   struct tm tm;
   int hour, mday, wday, month, wom, woy, ldom;
   /* Items corresponding to above at the next hour */
   int nh_hour, nh_mday, nh_wday, nh_month, nh_wom, nh_woy, nh_ldom;

   Dmsg0(dbglvl, "enter find_runs()\n");

   /* compute values for time now */
   now = time(NULL);
   (void)localtime_r(&now, &tm);
   hour = tm.tm_hour;
   mday = tm.tm_mday - 1;
   wday = tm.tm_wday;
   month = tm.tm_mon;
   wom = mday / 7;
   woy = tm_woy(now);                     /* get week of year */
   ldom = tm_ldom(month, tm.tm_year + 1900);

   Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
         now, hour, month, mday, wday, wom, woy);

   /*
    * Compute values for next hour from now.
    * We do this to be sure we don't miss a job while
    * sleeping.
    */
   next_hour = now + 3600;
   (void)localtime_r(&next_hour, &tm);
   nh_hour = tm.tm_hour;
   nh_mday = tm.tm_mday - 1;
   nh_wday = tm.tm_wday;
   nh_month = tm.tm_mon;
   nh_wom = nh_mday / 7;
   nh_woy = tm_woy(next_hour);              /* get week of year */
   nh_ldom = tm_ldom(nh_month, tm.tm_year + 1900);

   Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
         next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);

   /* Loop through all jobs */
   LockRes();
   foreach_res(job, R_JOB) {
      sched = job->schedule;
      if (!sched || !job->is_enabled() || (sched && !sched->is_enabled()) ||
         (job->client && !job->client->is_enabled())) {
         continue;                    /* no, skip this job */
      }
      Dmsg1(dbglvl, "Got job: %s\n", job->hdr.name);
      for (run=sched->run; run; run=run->next) {
         bool run_now, run_nh;
         /*
          * Find runs scheduled between now and the next hour.
          */
#ifdef xxxx
         Dmsg0(000, "\n");
         Dmsg7(000, "run h=%d m=%d md=%d wd=%d wom=%d woy=%d ldom=%d\n",
            hour, month, mday, wday, wom, woy, ldom);
         Dmsg7(000, "bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d bsldom=%d\n",
            bit_is_set(hour, run->hour),
            bit_is_set(month, run->month),
            bit_is_set(mday, run->mday),
            bit_is_set(wday, run->wday),
            bit_is_set(wom, run->wom),
            bit_is_set(woy, run->woy),
            bit_is_set(31, run->mday));


         Dmsg7(000, "nh_run h=%d m=%d md=%d wd=%d wom=%d woy=%d ldom=%d\n",
            nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy, nh_ldom);
         Dmsg7(000, "nh_bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d bsldom=%d\n",
            bit_is_set(nh_hour, run->hour),
            bit_is_set(nh_month, run->month),
            bit_is_set(nh_mday, run->mday),
            bit_is_set(nh_wday, run->wday),
            bit_is_set(nh_wom, run->wom),
            bit_is_set(nh_woy, run->woy),
            bit_is_set(31, run->mday));
#endif

         run_now = bit_is_set(hour, run->hour) &&
            ((bit_is_set(mday, run->mday) &&
              bit_is_set(wday, run->wday) &&
              bit_is_set(month, run->month) &&
              bit_is_set(wom, run->wom) &&
              bit_is_set(woy, run->woy)) ||
             (bit_is_set(month, run->month) &&
              bit_is_set(31, run->mday) && mday == ldom));

         run_nh = bit_is_set(nh_hour, run->hour) &&
            ((bit_is_set(nh_mday, run->mday) &&
              bit_is_set(nh_wday, run->wday) &&
              bit_is_set(nh_month, run->month) &&
              bit_is_set(nh_wom, run->wom) &&
              bit_is_set(nh_woy, run->woy)) ||
             (bit_is_set(nh_month, run->month) &&
              bit_is_set(31, run->mday) && nh_mday == nh_ldom));

         Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);

         if (run_now || run_nh) {
           /* find time (time_t) job is to be run */
           (void)localtime_r(&now, &tm);      /* reset tm structure */
           tm.tm_min = run->minute;     /* set run minute */
           tm.tm_sec = 0;               /* zero secs */
           runtime = mktime(&tm);
           if (run_now) {
             add_job(job, run, now, runtime);
           }
           /* If job is to be run in the next hour schedule it */
           if (run_nh) {
             add_job(job, run, now, runtime + 3600);
           }
         }
      }
   }
   UnlockRes();
   Dmsg0(dbglvl, "Leave find_runs()\n");
}
/*
 * Find all jobs to be run this hour and the next hour.
 */
Find all jobs to be run this hour and the next hour.
Find all jobs to be run this hour and the next hour .
static void find_runs()
{
   time_t now, next_hour, runtime;
   RUN *run;
   JOB *job;
   SCHED *sched;
   struct tm tm;
   int hour, mday, wday, month, wom, woy, ldom;
   int nh_hour, nh_mday, nh_wday, nh_month, nh_wom, nh_woy, nh_ldom;
   Dmsg0(dbglvl, "enter find_runs()\n");
   now = time(NULL);
   (void)localtime_r(&now, &tm);
   hour = tm.tm_hour;
   mday = tm.tm_mday - 1;
   wday = tm.tm_wday;
   month = tm.tm_mon;
   wom = mday / 7;
   woy = tm_woy(now);                     
   ldom = tm_ldom(month, tm.tm_year + 1900);
   Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
         now, hour, month, mday, wday, wom, woy);
   next_hour = now + 3600;
   (void)localtime_r(&next_hour, &tm);
   nh_hour = tm.tm_hour;
   nh_mday = tm.tm_mday - 1;
   nh_wday = tm.tm_wday;
   nh_month = tm.tm_mon;
   nh_wom = nh_mday / 7;
   nh_woy = tm_woy(next_hour);              
   nh_ldom = tm_ldom(nh_month, tm.tm_year + 1900);
   Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
         next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
   LockRes();
   foreach_res(job, R_JOB) {
      sched = job->schedule;
      if (!sched || !job->is_enabled() || (sched && !sched->is_enabled()) ||
         (job->client && !job->client->is_enabled())) {
         continue;                    
      }
      Dmsg1(dbglvl, "Got job: %s\n", job->hdr.name);
      for (run=sched->run; run; run=run->next) {
         bool run_now, run_nh;
#ifdef xxxx
         Dmsg0(000, "\n");
         Dmsg7(000, "run h=%d m=%d md=%d wd=%d wom=%d woy=%d ldom=%d\n",
            hour, month, mday, wday, wom, woy, ldom);
         Dmsg7(000, "bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d bsldom=%d\n",
            bit_is_set(hour, run->hour),
            bit_is_set(month, run->month),
            bit_is_set(mday, run->mday),
            bit_is_set(wday, run->wday),
            bit_is_set(wom, run->wom),
            bit_is_set(woy, run->woy),
            bit_is_set(31, run->mday));
         Dmsg7(000, "nh_run h=%d m=%d md=%d wd=%d wom=%d woy=%d ldom=%d\n",
            nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy, nh_ldom);
         Dmsg7(000, "nh_bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d bsldom=%d\n",
            bit_is_set(nh_hour, run->hour),
            bit_is_set(nh_month, run->month),
            bit_is_set(nh_mday, run->mday),
            bit_is_set(nh_wday, run->wday),
            bit_is_set(nh_wom, run->wom),
            bit_is_set(nh_woy, run->woy),
            bit_is_set(31, run->mday));
#endif
         run_now = bit_is_set(hour, run->hour) &&
            ((bit_is_set(mday, run->mday) &&
              bit_is_set(wday, run->wday) &&
              bit_is_set(month, run->month) &&
              bit_is_set(wom, run->wom) &&
              bit_is_set(woy, run->woy)) ||
             (bit_is_set(month, run->month) &&
              bit_is_set(31, run->mday) && mday == ldom));
         run_nh = bit_is_set(nh_hour, run->hour) &&
            ((bit_is_set(nh_mday, run->mday) &&
              bit_is_set(nh_wday, run->wday) &&
              bit_is_set(nh_month, run->month) &&
              bit_is_set(nh_wom, run->wom) &&
              bit_is_set(nh_woy, run->woy)) ||
             (bit_is_set(nh_month, run->month) &&
              bit_is_set(31, run->mday) && nh_mday == nh_ldom));
         Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);
         if (run_now || run_nh) {
           (void)localtime_r(&now, &tm);      
           tm.tm_min = run->minute;     
           tm.tm_sec = 0;               
           runtime = mktime(&tm);
           if (run_now) {
             add_job(job, run, now, runtime);
           }
           if (run_nh) {
             add_job(job, run, now, runtime + 3600);
           }
         }
      }
   }
   UnlockRes();
   Dmsg0(dbglvl, "Leave find_runs()\n");
}
static void find_runs ( ) { time_t now , next_hour , runtime ; RUN * run ; JOB * job ; SCHED * sched ; struct tm tm ; int hour , mday , wday , month , wom , woy , ldom ; int nh_hour , nh_mday , nh_wday , nh_month , nh_wom , nh_woy , nh_ldom ; Dmsg0 ( dbglvl , " \n " ) ; now = time ( NULL ) ; ( void ) localtime_r ( & now , & tm ) ; hour = tm . tm_hour ; mday = tm . tm_mday - 1 ; wday = tm . tm_wday ; month = tm . tm_mon ; wom = mday / 7 ; woy = tm_woy ( now ) ; ldom = tm_ldom ( month , tm . tm_year + 1900 ) ; Dmsg7 ( dbglvl , " \n " , now , hour , month , mday , wday , wom , woy ) ; next_hour = now + 3600 ; ( void ) localtime_r ( & next_hour , & tm ) ; nh_hour = tm . tm_hour ; nh_mday = tm . tm_mday - 1 ; nh_wday = tm . tm_wday ; nh_month = tm . tm_mon ; nh_wom = nh_mday / 7 ; nh_woy = tm_woy ( next_hour ) ; nh_ldom = tm_ldom ( nh_month , tm . tm_year + 1900 ) ; Dmsg7 ( dbglvl , " \n " , next_hour , nh_hour , nh_month , nh_mday , nh_wday , nh_wom , nh_woy ) ; LockRes ( ) ; foreach_res ( job , R_JOB ) { sched = job -> schedule ; if ( ! sched || ! job -> is_enabled ( ) || ( sched && ! sched -> is_enabled ( ) ) || ( job -> client && ! job -> client -> is_enabled ( ) ) ) { continue ; } Dmsg1 ( dbglvl , " \n " , job -> hdr . name ) ; for ( run = sched -> run ; run ; run = run -> next ) { bool run_now , run_nh ; #ifdef xxxx Dmsg0 ( 000 , " \n " ) ; Dmsg7 ( 000 , " \n " , hour , month , mday , wday , wom , woy , ldom ) ; Dmsg7 ( 000 , " \n " , bit_is_set ( hour , run -> hour ) , bit_is_set ( month , run -> month ) , bit_is_set ( mday , run -> mday ) , bit_is_set ( wday , run -> wday ) , bit_is_set ( wom , run -> wom ) , bit_is_set ( woy , run -> woy ) , bit_is_set ( 31 , run -> mday ) ) ; Dmsg7 ( 000 , " \n " , nh_hour , nh_month , nh_mday , nh_wday , nh_wom , nh_woy , nh_ldom ) ; Dmsg7 ( 000 , " \n " , bit_is_set ( nh_hour , run -> hour ) , bit_is_set ( nh_month , run -> month ) , bit_is_set ( nh_mday , run -> mday ) , bit_is_set ( nh_wday , run -> wday ) , bit_is_set ( nh_wom , run -> wom ) , bit_is_set ( nh_woy , run -> woy ) , bit_is_set ( 31 , run -> mday ) ) ; #endif run_now = bit_is_set ( hour , run -> hour ) && ( ( bit_is_set ( mday , run -> mday ) && bit_is_set ( wday , run -> wday ) && bit_is_set ( month , run -> month ) && bit_is_set ( wom , run -> wom ) && bit_is_set ( woy , run -> woy ) ) || ( bit_is_set ( month , run -> month ) && bit_is_set ( 31 , run -> mday ) && mday == ldom ) ) ; run_nh = bit_is_set ( nh_hour , run -> hour ) && ( ( bit_is_set ( nh_mday , run -> mday ) && bit_is_set ( nh_wday , run -> wday ) && bit_is_set ( nh_month , run -> month ) && bit_is_set ( nh_wom , run -> wom ) && bit_is_set ( nh_woy , run -> woy ) ) || ( bit_is_set ( nh_month , run -> month ) && bit_is_set ( 31 , run -> mday ) && nh_mday == nh_ldom ) ) ; Dmsg3 ( dbglvl , " \n " , run , run_now , run_nh ) ; if ( run_now || run_nh ) { ( void ) localtime_r ( & now , & tm ) ; tm . tm_min = run -> minute ; tm . tm_sec = 0 ; runtime = mktime ( & tm ) ; if ( run_now ) { add_job ( job , run , now , runtime ) ; } if ( run_nh ) { add_job ( job , run , now , runtime + 3600 ) ; } } } } UnlockRes ( ) ; Dmsg0 ( dbglvl , " \n " ) ; }
Find all jobs to be run this hour and the next hour.
Find all jobs to be run this hour and the next hour .
/* Items corresponding to above at the next hour */ /* compute values for time now */ /* get week of year */ /*
    * Compute values for next hour from now.
    * We do this to be sure we don't miss a job while
    * sleeping.
    */ /* get week of year */ /* Loop through all jobs */ /* no, skip this job */ /*
          * Find runs scheduled between now and the next hour.
          */ /* find time (time_t) job is to be run */ /* reset tm structure */ /* set run minute */ /* zero secs */ /* If job is to be run in the next hour schedule it */