add repair steps to get rid of old background jobs

This commit is contained in:
Arthur Schiwon 2015-05-12 18:19:44 +02:00
parent e016ed55ff
commit d6becb8d82
3 changed files with 120 additions and 0 deletions

View File

@ -32,6 +32,7 @@ use OC\Hooks\Emitter;
use OC\Repair\AssetCache;
use OC\Repair\CleanTags;
use OC\Repair\Collation;
use OC\Repair\DropOldJobs;
use OC\Repair\SqliteAutoincrement;
use OC\Repair\DropOldTables;
use OC\Repair\FillETags;
@ -106,6 +107,7 @@ class Repair extends BasicEmitter {
new FillETags(\OC_DB::getConnection()),
new CleanTags(\OC_DB::getConnection()),
new DropOldTables(\OC_DB::getConnection()),
new DropOldJobs(\OC::$server->getJobList()),
);
}

View File

@ -0,0 +1,78 @@
<?php
/**
* @author Arthur Schiwon <blizzz@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\BackgroundJob\IJobList;
class DropOldJobs extends BasicEmitter implements RepairStep {
/** @var IJobList */
protected $jobList;
/**
* @param IJobList $jobList
*/
public function __construct(IJobList $jobList) {
$this->jobList = $jobList;
}
/**
* Returns the step's name
*
* @return string
*/
public function getName() {
return 'Drop old background jobs';
}
/**
* Run repair step.
* Must throw exception on error.
*
* @throws \Exception in case of failure
*/
public function run() {
$oldJobs = $this->oldJobs();
foreach($oldJobs as $job) {
if($this->jobList->has($job['class'], $job['arguments'])) {
$this->jobList->remove($job['class'], $job['arguments']);
}
}
}
/**
* returns a list of old jobs as an associative array with keys 'class' and
* 'arguments'.
*
* @return array
*/
public function oldJobs() {
return [
['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
];
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Copyright (c) 2015 Arthur Schiwon <blizzz@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace Test\Repair;
use OCP\BackgroundJob\IJobList;
/**
* Tests for the dropping old tables
*
* @see \OC\Repair\DropOldTables
*/
class DropOldJobs extends \Test\TestCase {
/** @var IJobList */
protected $jobList;
protected function setUp() {
parent::setUp();
$this->jobList = \OC::$server->getJobList();
$this->jobList->add('OC\Cache\FileGlobalGC');
$this->jobList->add('OC_Cache_FileGlobalGC');
}
public function testRun() {
$this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing');
$this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
$repair = new \OC\Repair\DropOldJobs($this->jobList);
$repair->run();
$this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing');
$this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');
}
}