Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15400877
D17539.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D17539.id.diff
View Options
diff --git a/src/daemon/PhutilDaemonOverseerModule.php b/src/daemon/PhutilDaemonOverseerModule.php
--- a/src/daemon/PhutilDaemonOverseerModule.php
+++ b/src/daemon/PhutilDaemonOverseerModule.php
@@ -7,13 +7,17 @@
*/
abstract class PhutilDaemonOverseerModule extends Phobject {
+ private $throttles = array();
+
/**
* This method is used to indicate to the overseer that daemons should reload.
*
* @return bool True if the daemons should reload, otherwise false.
*/
- abstract public function shouldReloadDaemons();
+ public function shouldReloadDaemons() {
+ return false;
+ }
/**
@@ -32,4 +36,36 @@
->execute();
}
+
+ /**
+ * Throttle checks from executing too often.
+ *
+ * If you throttle a check like this, it will only execute once every 2.5
+ * seconds:
+ *
+ * if ($this->shouldThrottle('some.check', 2.5)) {
+ * return;
+ * }
+ *
+ * @param string Throttle key.
+ * @param float Duration in seconds.
+ * @return bool True to throttle the check.
+ */
+ protected function shouldThrottle($name, $duration) {
+ $throttle = idx($this->throttles, $name, 0);
+ $now = microtime(true);
+
+ // If not enough time has elapsed, throttle the check.
+ $elapsed = ($now - $throttle);
+ if ($elapsed < $duration) {
+ return true;
+ }
+
+ // Otherwise, mark the current time as the last time we ran the check,
+ // then let it continue.
+ $this->throttles[$name] = $now;
+
+ return false;
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 18, 2:28 PM (4 d, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7611304
Default Alt Text
D17539.id.diff (1 KB)
Attached To
Mode
D17539: Clean up overseer modules slightly and provide a throttling support method
Attached
Detach File
Event Timeline
Log In to Comment