Differential D16739 Diff 40313 src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | final public function runCollector() { | ||||
// retention policy. | // retention policy. | ||||
if (!$this->hasAutomaticPolicy()) { | if (!$this->hasAutomaticPolicy()) { | ||||
$policy = $this->getRetentionPolicy(); | $policy = $this->getRetentionPolicy(); | ||||
if (!$policy) { | if (!$policy) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return $this->collectGarbage(); | // Hold a lock while performing collection to avoid racing other daemons | ||||
// running the same collectors. | |||||
$lock_name = 'gc:'.$this->getCollectorConstant(); | |||||
$lock = PhabricatorGlobalLock::newLock($lock_name); | |||||
try { | |||||
$lock->lock(5); | |||||
} catch (PhutilLockException $ex) { | |||||
return false; | |||||
} | |||||
try { | |||||
$result = $this->collectGarbage(); | |||||
} catch (Exception $ex) { | |||||
$lock->unlock(); | |||||
throw $ex; | |||||
} | |||||
$lock->unlock(); | |||||
return $result; | |||||
} | } | ||||
/** | /** | ||||
* Collect garbage from whatever source this GC handles. | * Collect garbage from whatever source this GC handles. | ||||
* | * | ||||
* @return bool True if there is more garbage to collect. | * @return bool True if there is more garbage to collect. | ||||
* @task collect | * @task collect | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |