Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| TaskService | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| runQueue | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
72 | |||
| getLimit | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2014 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\oatbox\task; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use common_report_Report as Report; |
| 27 | |
| 28 | /** |
| 29 | * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\QueueDispatcher instead. |
| 30 | */ |
| 31 | class TaskService extends ConfigurableService |
| 32 | { |
| 33 | /** |
| 34 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 35 | */ |
| 36 | public const TASK_QUEUE_MANAGER_ROLE = 'http://www.tao.lu/Ontologies/TAO.rdf#TaskQueueManager'; |
| 37 | |
| 38 | /** |
| 39 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 40 | */ |
| 41 | public const OPTION_LIMIT = 'limit'; |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 46 | * |
| 47 | * @return Report |
| 48 | * @throws \common_exception_Error |
| 49 | */ |
| 50 | public function runQueue() |
| 51 | { |
| 52 | $count = 0; |
| 53 | $statistics = []; |
| 54 | $queue = $this->getServiceManager()->get(Queue::CONFIG_ID); |
| 55 | $report = new Report(Report::TYPE_SUCCESS); |
| 56 | $limit = $this->getLimit(); |
| 57 | foreach ($queue as $task) { |
| 58 | $subReport = $queue->runTask($task); |
| 59 | $statistics[$subReport->getType()] = isset($statistics[$subReport->getType()]) |
| 60 | ? $statistics[$subReport->getType()] + 1 |
| 61 | : 1; |
| 62 | $report->add($subReport); |
| 63 | $count++; |
| 64 | if ($limit !== 0 && $count === $limit) { |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (empty($statistics)) { |
| 70 | $report = new Report(Report::TYPE_INFO, __('No tasks to run')); |
| 71 | } else { |
| 72 | if (isset($statistics[Report::TYPE_ERROR]) || isset($statistics[Report::TYPE_WARNING])) { |
| 73 | $report->setType(Report::TYPE_WARNING); |
| 74 | } |
| 75 | $report->setMessage(__('Ran %s task(s):', array_sum($statistics))); |
| 76 | } |
| 77 | return $report; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @return int |
| 82 | */ |
| 83 | private function getLimit() |
| 84 | { |
| 85 | $limit = $this->hasOption(self::OPTION_LIMIT) ? $this->getOption(self::OPTION_LIMIT) : 0; |
| 86 | return (int) $limit; |
| 87 | } |
| 88 | } |