/** * 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 __destruct() { if (!empty($this->pid_file) && file_exists($this->pid_file)) { if (!unlink($this->pid_file)) { Log::warning("Could not delete pid file " . $this->pid_file); } } }
/** * Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a MySQLi_Result object. For other successful queries mysqli_query() will return TRUE. */ public function query($sql) { $this->lastSql = $sql; $begin = intval(microtime(true) * 1000000); $this->connect(); $res = $this->mysqli->query($sql); #reconnect max times 3 for ($i = 0; $i < 3; $i++) { if (in_array($this->mysqli->errno, $this->retryErrno)) { Log::warning("db reconnect. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql:{$sql}]"); usleep(100000); $this->connect(true); $res = $this->mysqli->query($sql); } else { break; } } if (false === $res) { Log::warning("db error. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql: {$sql}]"); } $this->lastCost = intval(microtime(true) * 1000000) - $begin; $this->totalCost += $this->lastCost; Log::debug('query success. [cost: ' . $this->lastCost . 'us] [sql: ' . $sql . ']'); return $res; }