Path: blob/master/src/infrastructure/daemon/PhutilDaemonOverseerModule.php
12241 views
<?php12/**3* Overseer modules allow daemons to be externally influenced.4*5* See @{class:PhabricatorDaemonOverseerModule} for a concrete example.6*/7abstract class PhutilDaemonOverseerModule extends Phobject {89private $throttles = array();101112/**13* This method is used to indicate to the overseer that daemons should reload.14*15* @return bool True if the daemons should reload, otherwise false.16*/17public function shouldReloadDaemons() {18return false;19}202122/**23* Should a hibernating daemon pool be awoken immediately?24*25* @return bool True to awaken the pool immediately.26*/27public function shouldWakePool(PhutilDaemonPool $pool) {28return false;29}303132public static function getAllModules() {33return id(new PhutilClassMapQuery())34->setAncestorClass(__CLASS__)35->execute();36}373839/**40* Throttle checks from executing too often.41*42* If you throttle a check like this, it will only execute once every 2.543* seconds:44*45* if ($this->shouldThrottle('some.check', 2.5)) {46* return;47* }48*49* @param string Throttle key.50* @param float Duration in seconds.51* @return bool True to throttle the check.52*/53protected function shouldThrottle($name, $duration) {54$throttle = idx($this->throttles, $name, 0);55$now = microtime(true);5657// If not enough time has elapsed, throttle the check.58$elapsed = ($now - $throttle);59if ($elapsed < $duration) {60return true;61}6263// Otherwise, mark the current time as the last time we ran the check,64// then let it continue.65$this->throttles[$name] = $now;6667return false;68}6970}717273