/** * daemon: rely check */ public function runAction(&$log) { $oTask = new Task(); $oRely = new Rely(); while (true) { Log::info("loop check rely."); $taskArr = $oTask->pending(); foreach ($taskArr as $task) { $ready = true; $relyArr = $oRely->job($task['job_id']); foreach ($relyArr as $rely) { $ready = $oTask->check($task['time'], $rely['rely_job'], $rely['start'], $rely['long'], $rely['freq']); Log::info("rely check [job_id:" . $task['job_id'] . "] [rely_job:" . $rely['rely_job'] . "] [time:" . $task['time'] . "] [ready:" . intval($ready) . "]"); if (!$ready) { break; } } if ($ready) { Log::info("rely ready [job_id:" . $task['job_id'] . "] [time:" . $task['time'] . "]"); $oTask->setReady($task['job_id'], $task['time']); } } sleep(3); } }
/** * daemon:dispatch ready tasks */ public function runAction(&$log) { $oTask = new Task(); $oJob = new Job(); while (true) { Log::info("loop dispatch."); $taskArr = $oTask->ready(); foreach ($taskArr as $task) { Log::info("dispatch [job_id:" . $task['job_id'] . "] [time:" . $task['time'] . "]"); $oJob->dispatch($task['job_id'], $task['time']); } sleep(3); } }
public function run() { $pid = $this->mypid; $app = $this->app; $action = $this->action . 'Action'; Log::info("Begin to execute. [app:{$app} action:{$action} pid:{$pid}]"); $class = $this->format($app); if (!class_exists($class)) { Log::fatal("Failed to find class:{$class}"); return; } $obj = new $class($this->params); if (!method_exists($obj, $action)) { Log::fatal("Failed to find method:{$action}"); return; } Log::info("Calling method[{$action}] for {$app}."); $log = array(); $result = $obj->{$action}($log); //log if (!empty($log)) { foreach ($log as $l) { if (!is_scalar($l)) { $l = explode("\n", trim(print_r($l, true))); } elseif (strlen($l) > 256) { $l = substr($l, 0, 256) . '...(truncated)'; } if (is_array($l)) { foreach ($l as $ln) { Log::info($ln); } } else { Log::info($l); } } } //result if (!is_scalar($result)) { $result = explode("\n", trim(print_r($result, true))); } elseif (strlen($result) > 256) { $result = substr($result, 0, 256) . '...(truncated)'; } if (is_array($result)) { foreach ($result as $ln) { Log::debug($ln); } } else { Log::debug($result); } Log::info("Execute finished. [app:{$app} action:{$action} process id:{$pid}]"); }