Esempio n. 1
0
 public function run($data)
 {
     /*{{{*/
     switch ($data['type']) {
         case 'tasks':
             $conf = json_encode($data['data']);
             file_put_contents($this->conf_file, $conf);
             CronLogger::info("Get new tasks: " . $conf . "\n");
             CronLogger::message(array('type' => 'host-sync', 'host' => $data['host'], 'user' => $data['user'], 'time' => time()));
             break;
         case 'cmd':
             $this->handleCommand($data);
             break;
         case 'ping':
             CronLogger::message(array('type' => 'ping', 'host' => php_uname('n'), 'version' => VERSION));
             break;
     }
 }
Esempio n. 2
0
 public function report()
 {
     /*{{{*/
     CronLogger::info(json_encode($this->last_execute_info));
     CronLogger::message(array('type' => 'task-run', 'id' => $this->id, 'user' => $this->user, 'time' => time(), 'result' => $this->last_execute_info));
 }
Esempio n. 3
0
 private function _doTask($task)
 {
     /*{{{*/
     $task->setIsRunning();
     $pid = pcntl_fork();
     if ($pid === 0) {
         $child_pid = pcntl_fork();
         if ($child_pid === 0) {
             CronLogger::info("Start task " . $task->rule);
             $task->run();
             $task->report();
         } else {
             if ($child_pid < 0) {
                 CronLogger::err("Start task " . $task->rule . " failed");
             }
         }
         exit(0);
     } else {
         if ($pid < 0) {
             CronLogger::err("Start task " . $task->rule . " failed");
         }
     }
     return $pid;
 }