Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F539943
PhutilDaemonOverseerModule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilDaemonOverseerModule.php
View Options
<?php
/**
* Overseer modules allow daemons to be externally influenced.
*
* See @{class:PhabricatorDaemonOverseerModule} for a concrete example.
*/
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.
*/
public
function
shouldReloadDaemons
()
{
return
false
;
}
/**
* Should a hibernating daemon pool be awoken immediately?
*
* @return bool True to awaken the pool immediately.
*/
public
function
shouldWakePool
(
PhutilDaemonPool
$pool
)
{
return
false
;
}
public
static
function
getAllModules
()
{
return
id
(
new
PhutilClassMapQuery
())
->
setAncestorClass
(
__CLASS__
)
->
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 $name Throttle key.
* @param float $duration 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/x-php
Expires
Mon, May 12, 9:22 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
120348
Default Alt Text
PhutilDaemonOverseerModule.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment