toImmutable(); // Crowns that are due appear, and a holder who kept them long enough wins. Seasons::tick($now); // Once a minute: abandoned accounts lose their villages to the barbarians. if ($now->getTimestamp() - $lastAbandonCheck >= 60) { $lastAbandonCheck = $now->getTimestamp(); Abandon::inactive($now); } while ($villageId = $engine->nextDueVillage($now)) { try { $engine->catchUp($villageId, $now); } catch (Throwable $e) { report($e); $engine->recordFailure($villageId, $now); } Push::villages([$villageId]); } if ($this->option('once')) { return self::SUCCESS; } // Sleep until the next event, at most a second, so new events are picked up. $next = $engine->nextFireAt(); $wait = $next ? ($next->getTimestampMs() - now()->getTimestampMs()) / 1000 : 1.0; usleep((int) (max(0.05, min(1.0, $wait)) * 1_000_000)); } while (true); } }