Merge pull request #22832 from owncloud/external-unavailable-recheck9
[9.0] allow availability recheck for external storages
This commit is contained in:
commit
434747f450
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace OCA\Files_External\Config;
|
namespace OCA\Files_External\Config;
|
||||||
|
|
||||||
|
use OC\Files\Storage\Wrapper\Availability;
|
||||||
use OCA\Files_external\Migration\StorageMigrator;
|
use OCA\Files_external\Migration\StorageMigrator;
|
||||||
use OCP\Files\Storage;
|
use OCP\Files\Storage;
|
||||||
use OC\Files\Mount\MountPoint;
|
use OC\Files\Mount\MountPoint;
|
||||||
|
@ -34,6 +35,7 @@ use OCA\Files_external\Service\UserStoragesService;
|
||||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||||
use OCA\Files_External\Lib\StorageConfig;
|
use OCA\Files_External\Lib\StorageConfig;
|
||||||
use OCA\Files_External\Lib\FailedStorage;
|
use OCA\Files_External\Lib\FailedStorage;
|
||||||
|
use OCP\Files\StorageNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the old files_external config work with the new public mount config api
|
* Make the old files_external config work with the new public mount config api
|
||||||
|
@ -132,8 +134,10 @@ class ConfigAdapter implements IMountProvider {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$availability = $impl->getAvailability();
|
$availability = $impl->getAvailability();
|
||||||
if (!$availability['available']) {
|
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
|
||||||
$impl = new FailedStorage(['exception' => null]);
|
$impl = new FailedStorage([
|
||||||
|
'exception' => new StorageNotAvailableException('Storage with mount id ' . $storage->getId() . ' is not available')
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// propagate exception into filesystem
|
// propagate exception into filesystem
|
||||||
|
|
|
@ -39,6 +39,9 @@ class FailedStorage extends Common {
|
||||||
*/
|
*/
|
||||||
public function __construct($params) {
|
public function __construct($params) {
|
||||||
$this->e = $params['exception'];
|
$this->e = $params['exception'];
|
||||||
|
if (!$this->e) {
|
||||||
|
throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId() {
|
public function getId() {
|
||||||
|
|
|
@ -29,6 +29,16 @@ namespace OC\Files\Storage\Wrapper;
|
||||||
class Availability extends Wrapper {
|
class Availability extends Wrapper {
|
||||||
const RECHECK_TTL_SEC = 600; // 10 minutes
|
const RECHECK_TTL_SEC = 600; // 10 minutes
|
||||||
|
|
||||||
|
public static function shouldRecheck($availability) {
|
||||||
|
if (!$availability['available']) {
|
||||||
|
// trigger a recheck if TTL reached
|
||||||
|
if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -47,11 +57,8 @@ class Availability extends Wrapper {
|
||||||
*/
|
*/
|
||||||
private function isAvailable() {
|
private function isAvailable() {
|
||||||
$availability = $this->getAvailability();
|
$availability = $this->getAvailability();
|
||||||
if (!$availability['available']) {
|
if (self::shouldRecheck($availability)) {
|
||||||
// trigger a recheck if TTL reached
|
return $this->updateAvailability();
|
||||||
if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) {
|
|
||||||
return $this->updateAvailability();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $availability['available'];
|
return $availability['available'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue