Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 24  | 
               | 
       0.00%  | 
       0 / 1  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| TaskRunner |         | 
       0.00%  | 
       0 / 24  | 
               | 
       0.00%  | 
       0 / 1  | 
       20 |         | 
       0.00%  | 
       0 / 1  | 
      
| run |         | 
       0.00%  | 
       0 / 24  | 
               | 
       0.00%  | 
       0 / 1  | 
       20 | |||
| 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-2017 (original work) Open Assessment Technologies SA; | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\oatbox\task; | 
| 23 | |
| 24 | use oat\oatbox\action\ActionService; | 
| 25 | use oat\oatbox\task\TaskInterface\TaskQueue; | 
| 26 | use Zend\ServiceManager\ServiceLocatorAwareInterface; | 
| 27 | use oat\oatbox\task\TaskInterface\TaskRunner as TaskRunnerInterface; | 
| 28 | use Zend\ServiceManager\ServiceLocatorAwareTrait; | 
| 29 | use common_report_Report as Report; | 
| 30 | |
| 31 | /** | 
| 32 | * @deprecated since version 7.10.0, to be removed in 8.0. Use any implementation of | 
| 33 | * \oat\tao\model\taskQueue\Worker\WorkerInterface instead. | 
| 34 | */ | 
| 35 | class TaskRunner implements TaskRunnerInterface | 
| 36 | { | 
| 37 | use ServiceLocatorAwareTrait; | 
| 38 | |
| 39 | /** | 
| 40 | * @deprecated since version 7.10.0, to be removed in 8.0. | 
| 41 | */ | 
| 42 | public function run(Task $task) | 
| 43 | { | 
| 44 | |
| 45 | \common_Logger::d('Running task ' . $task->getId()); | 
| 46 | $report = new Report( | 
| 47 | \common_report_Report::TYPE_INFO, | 
| 48 | __('Running task %s at %s', $task->getId(), microtime(true)) | 
| 49 | ); | 
| 50 | /** @var TaskQueue $queue */ | 
| 51 | $queue = $this->getServiceLocator()->get(Queue::SERVICE_ID); | 
| 52 | $queue->updateTaskStatus($task->getId(), Task::STATUS_RUNNING); | 
| 53 | try { | 
| 54 | $actionService = $this->getServiceLocator()->get(ActionService::SERVICE_ID); | 
| 55 | $invocable = $task->getInvocable(); | 
| 56 | if (is_string($invocable)) { | 
| 57 | $invocable = $actionService->resolve($task->getInvocable()); | 
| 58 | } elseif ($invocable instanceof ServiceLocatorAwareInterface) { | 
| 59 | $invocable->setServiceLocator($this->getServiceLocator()); | 
| 60 | } | 
| 61 | $subReport = call_user_func($invocable, $task->getParameters()); | 
| 62 | $report->add($subReport); | 
| 63 | $report->setMessage($report->getMessage() . '; ' . __('Finished at %s', microtime(true))); | 
| 64 | } catch (\Exception $e) { | 
| 65 | $message = __('Failed at %s; Error message: %s', microtime(true), $e->getMessage()); | 
| 66 | \common_Logger::e($message); | 
| 67 | $report->setType(Report::TYPE_ERROR); | 
| 68 | $report->setMessage($report->getMessage() . '; ' . $message); | 
| 69 | } | 
| 70 | $queue->updateTaskStatus($task->getId(), Task::STATUS_FINISHED); | 
| 71 | $queue->updateTaskReport($task->getId(), $report); | 
| 72 | return $report; | 
| 73 | } | 
| 74 | } |