예제 #1
0
 /**
  * @static
  *
  * @param $arg
  * @internal param $args
  */
 public static function run($arg)
 {
     $job_object = BackWPup_Job::get_working_data();
     if ($arg == 'restart' && !empty($job_object)) {
         //reschedule restart
         wp_schedule_single_event(time() + 60, 'backwpup_cron', array('id' => 'restart'));
         //restart job if not working or a restart imitated
         $not_worked_time = microtime(TRUE) - $job_object->timestamp_last_update;
         if (empty($job_object->pid) || $not_worked_time > 300) {
             BackWPup_Job::start_wp_cron();
         }
         return;
     }
     if (empty($arg) || $arg == 'restart') {
         return;
     }
     //check that job exits
     $jobids = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!in_array($arg, $jobids)) {
         return;
     }
     //delay other job start for 5 minutes if already one is running
     if (!empty($job_object)) {
         wp_schedule_single_event(time() + 300, 'backwpup_cron', array('id' => $arg));
         return;
     }
     //reschedule next job run
     $cron_next = self::cron_next(BackWPup_Option::get($arg, 'cron'));
     wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $arg));
     //start job
     BackWPup_Job::start_wp_cron($arg);
 }