diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-08-18 23:07:20 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-08-18 23:07:20 +0300 |
commit | 6de2f3692ff7fdff9938a75da72d3e1dc2869aff (patch) | |
tree | a8bfbf3656650080ba68a072bd8f47244fbfb589 /lib | |
parent | 5e0105e43561999c60693018ebceadd89f979b37 (diff) |
manage error during cron
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Cron/Index.php | 39 | ||||
-rw-r--r-- | lib/Db/CoreRequestBuilder.php | 12 | ||||
-rw-r--r-- | lib/Db/IndexesRequest.php | 8 | ||||
-rw-r--r-- | lib/Service/ConfigService.php | 4 | ||||
-rw-r--r-- | lib/Service/IndexService.php | 8 |
5 files changed, 65 insertions, 6 deletions
diff --git a/lib/Cron/Index.php b/lib/Cron/Index.php index f8d38fc..bd78d8f 100644 --- a/lib/Cron/Index.php +++ b/lib/Cron/Index.php @@ -32,6 +32,7 @@ use OC\BackgroundJob\TimedJob; use OCA\FullTextSearch\AppInfo\Application; use OCA\FullTextSearch\Exceptions\InterruptException; use OCA\FullTextSearch\Model\Runner; +use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\IndexService; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\PlatformService; @@ -43,9 +44,15 @@ use OCP\IUserManager; class Index extends TimedJob { + const HOUR_ERR_RESET = 240; + + /** @var IUserManager */ private $userManager; + /** @var ConfigService */ + private $configService; + /** @var IndexService */ private $indexService; @@ -79,6 +86,7 @@ class Index extends TimedJob { $runningService = $c->query(RunningService::class); $this->runner = new Runner($runningService, 'cronIndex'); + $this->configService = $c->query(ConfigService::class); $this->indexService = $c->query(IndexService::class); $this->platformService = $c->query(PlatformService::class); $this->providerService = $c->query(ProviderService::class); @@ -102,7 +110,8 @@ class Index extends TimedJob { private function liveCycle() { $platform = $this->platformService->getPlatform(true); - $indexes = $this->indexService->getQueuedIndexes(); + $all = $this->shouldWeGetAllIndex(); + $indexes = $this->indexService->getQueuedIndexes($all); foreach ($indexes as $index) { $this->runner->updateAction('indexing'); @@ -121,6 +130,34 @@ class Index extends TimedJob { } } + } + + /** + * @return bool + */ + private function shouldWeGetAllIndex() { + $lastErrReset = (int)$this->configService->getAppValue(ConfigService::CRON_LAST_ERR_RESET); + + if ($lastErrReset === 0) { + $this->setLastErrReset(); + + return false; + } + + if ($lastErrReset < (time() - (self::HOUR_ERR_RESET * 3600))) { + $this->setLastErrReset(); + + return true; + } + + return false; + } + + /** + * + */ + private function setLastErrReset() { + $this->configService->setAppValue(ConfigService::CRON_LAST_ERR_RESET, time()); } } diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 84892fc..d1223e4 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -123,7 +123,6 @@ class CoreRequestBuilder { * Limit to the documentId * * @param IQueryBuilder $qb - * @param string $documentId */ protected function limitToErr(IQueryBuilder &$qb) { $expr = $qb->expr(); @@ -132,6 +131,17 @@ class CoreRequestBuilder { /** + * Limit to the documentId + * + * @param IQueryBuilder $qb + */ + protected function limitToNoErr(IQueryBuilder &$qb) { + $expr = $qb->expr(); + $qb->andWhere($expr->eq('err', $qb->createNamedParameter(0))); + } + + + /** * Limit to documentIds * * @param IQueryBuilder $qb diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php index 4bb4925..edb7eac 100644 --- a/lib/Db/IndexesRequest.php +++ b/lib/Db/IndexesRequest.php @@ -148,6 +148,7 @@ class IndexesRequest extends IndexesRequestBuilder { } $qb->set('message', $qb->createNamedParameter(json_encode($index->getErrors()))); + $qb->set('err', $qb->createNamedParameter($index->getErrorCount())); $this->limitToProviderId($qb, $index->getProviderId()); $this->limitToDocumentId($qb, $index->getDocumentId()); @@ -258,11 +259,16 @@ class IndexesRequest extends IndexesRequestBuilder { /** + * @param bool $all + * * @return Index[] */ - public function getQueuedIndexes() { + public function getQueuedIndexes($all = false) { $qb = $this->getIndexesSelectSql(); $this->limitToQueuedIndexes($qb); + if ($all === false) { + $this->limitToNoErr($qb); + } $indexes = []; $cursor = $qb->execute(); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index a08a163..aa89352 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -38,13 +38,15 @@ class ConfigService { const SEARCH_PLATFORM = 'search_platform'; const CHUNK_INDEX = 'index_chunk'; const PROVIDER_INDEXED = 'provider_indexed'; + const CRON_LAST_ERR_RESET = 'cron_err_reset'; /** @var array */ public $defaults = [ self::SEARCH_PLATFORM => '', self::CHUNK_INDEX => '20', self::APP_NAVIGATION => '0', - self::PROVIDER_INDEXED => '' + self::PROVIDER_INDEXED => '', + self::CRON_LAST_ERR_RESET => '0' ]; /** @var IConfig */ diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 63bcee0..00e8d9c 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -420,6 +420,8 @@ class IndexService { return; } + $document->getIndex() + ->resetErrors(); $index = $platform->indexDocument($provider, $document); $this->updateIndex($index); } @@ -555,10 +557,12 @@ class IndexService { /** + * @param bool $all + * * @return Index[] */ - public function getQueuedIndexes() { - return $this->indexesRequest->getQueuedIndexes(); + public function getQueuedIndexes($all = false) { + return $this->indexesRequest->getQueuedIndexes($all); } |