Experimenting with TTL for ignored devices
Publish PHP Package / docker (push) Successful in 7s
Details
Publish PHP Package / docker (push) Successful in 7s
Details
This commit is contained in:
parent
f090413392
commit
69267565b1
|
@ -51,6 +51,7 @@ class SessionConfig
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
const RUN_SLEEP = 3;
|
const RUN_SLEEP = 3;
|
||||||
|
const IGNORE_DEVICE_TTL = 300;
|
||||||
|
|
||||||
public string $name;
|
public string $name;
|
||||||
public SessionConfig $conf;
|
public SessionConfig $conf;
|
||||||
|
@ -111,18 +112,30 @@ class Session
|
||||||
|
|
||||||
function getDevices() : array
|
function getDevices() : array
|
||||||
{
|
{
|
||||||
$devices = array_diff(
|
$this->_checkIgnoredDevices();
|
||||||
$this->device_pool->get(),
|
|
||||||
$this->ignored_devices
|
$connected_devices = $this->device_pool->get();
|
||||||
);
|
$actual_devices = array_diff($connected_devices, array_keys($this->ignored_devices));
|
||||||
return $devices;
|
|
||||||
|
return $actual_devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _checkIgnoredDevices()
|
||||||
|
{
|
||||||
|
//let's remove from ignored devices devices which were ignored for some time
|
||||||
|
$devices = array_keys($this->ignored_devices);
|
||||||
|
foreach($devices as $device)
|
||||||
|
{
|
||||||
|
if(time() - $this->ignored_devices[$device] > self::IGNORE_DEVICE_TTL)
|
||||||
|
unset($this->ignored_devices[$device]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ignoreDevice(string $device, string $reason)
|
function ignoreDevice(string $device, string $reason)
|
||||||
{
|
{
|
||||||
err("Ignoring device *$device*: $reason");
|
err("Ignoring device *$device*: $reason");
|
||||||
|
|
||||||
$this->ignored_devices[] = $device;
|
$this->ignored_devices[$device] = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
function incBogusDevice(string $device)
|
function incBogusDevice(string $device)
|
||||||
|
|
Loading…
Reference in New Issue