@ -6,16 +6,32 @@ use App\BOB;
@@ -6,16 +6,32 @@ use App\BOB;
use App\DB;
use Amp\Loop;
use Amp\Parallel\Worker\DefaultPool;
use Amp\TimeoutException;
/* Disable execution limit */
set_time_limit(0);
$pdo = (new DB($options))->pdo;
$lockfile = __DIR__ . '/checker.lock';
$full = false;
$results = [];
if($argc == 2 && $argv[1] == "full") {
$full = true;
}
echo "[CHECKER] Checking lockfile" . PHP_EOL;
$fp = fopen($lockfile, 'c');
if(!flock($fp, LOCK_EX | LOCK_NB)) {
echo "[CHECKER] Looks like another checker is running, exiting..." . PHP_EOL;
exit(-1);
}
echo "[DB] Fetching hosts to check from database" . PHP_EOL;
if ((($options['fullhour'] >= 0) && ($options['fullhour'] <= 23)) && date('H') == $options['fullhour']) { // check all hosts at full check hour
if ((($options['fullhour'] >= 0) && ($options['fullhour'] <= 23)) && date('H') == $options['fullhour'] || $full) { // check all hosts at full check hour or when argument 'full' passed
echo "[CHECKER] Starting FULL check" . PHP_EOL;
$STH = $pdo->query("SELECT `host`, `base32` FROM `hosts`");
} else {
@ -41,21 +57,27 @@ if ($bob->setnick()) {
@@ -41,21 +57,27 @@ if ($bob->setnick()) {
}
/* Start async checker tasks */
Loop::run(function () use (&$results, $hosts, $options) {
$pool = new DefaultPool($options['checkthreads']);
try {
Loop::run(function () use (&$results, $hosts, $options) {
$pool = new DefaultPool($options['checkthreads']);
$coroutines = [];
$coroutines = [];
foreach ($hosts as $host => $base32) {
$coroutines[$host] = Amp\call(function () use ($pool, $base32, $options) {