Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SyncQueue | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| createTask | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| getIterator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| linkTask | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\task\implementation; |
| 23 | |
| 24 | use oat\oatbox\task\AbstractQueue; |
| 25 | use oat\oatbox\task\Task; |
| 26 | use oat\oatbox\task\TaskRunner; |
| 27 | use common_report_Report as Report; |
| 28 | |
| 29 | /** |
| 30 | * Class SyncQueue |
| 31 | * |
| 32 | * Basic implementation of task queue. Created task will be executed immediately after creation |
| 33 | * in the same process. |
| 34 | * |
| 35 | * Usage example: |
| 36 | * ``` |
| 37 | * $queue = \oat\oatbox\service\ServiceManager::getServiceManager()->get(SyncQueue::CONFIG_ID); |
| 38 | * $queue->createTask(new SendReport(), [$resource->getUri()]); //task will be created and executed immediately |
| 39 | * ``` |
| 40 | * |
| 41 | * @package oat\oatbox\task\implementation |
| 42 | * @author Aleh Hutnikau, <huntikau@1pt.com> |
| 43 | * |
| 44 | * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\QueueDispatcher instead. |
| 45 | */ |
| 46 | class SyncQueue extends AbstractQueue |
| 47 | { |
| 48 | /** |
| 49 | * @var TaskRunner |
| 50 | */ |
| 51 | protected $taskRunner; |
| 52 | |
| 53 | /** |
| 54 | * Create and run task |
| 55 | * |
| 56 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 57 | * |
| 58 | * @param \oat\oatbox\action\Action|string $action action instance, classname or callback function |
| 59 | * @param array $parameters parameters to be passed to the action |
| 60 | * @param boolean $recall Parameter which indicates that task has been created repeatedly after fail of previous. |
| 61 | * For current implementation in means that the second call will not be executed to avoid loop. |
| 62 | * @param null|string $label |
| 63 | * @param null|string $type |
| 64 | * @return SyncTask |
| 65 | */ |
| 66 | public function createTask($action, $parameters, $recall = false, $label = null, $type = null) |
| 67 | { |
| 68 | if ($recall) { |
| 69 | \common_Logger::w("Repeated call of action'; Execution canceled."); |
| 70 | return false; |
| 71 | } |
| 72 | $task = new SyncTask($action, $parameters); |
| 73 | $task->setLabel($label); |
| 74 | $task->setType($type); |
| 75 | $this->getPersistence()->add($task); |
| 76 | $this->runTask($task); |
| 77 | return $task; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * not implemented |
| 82 | * |
| 83 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 84 | */ |
| 85 | public function getIterator() |
| 86 | { |
| 87 | return new TaskList($this->getPersistence()->getAll()); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Create task resource in the rdf storage and link placeholder resource to it. |
| 92 | * |
| 93 | * @deprecated since version 7.10.0, to be removed in 8.0. |
| 94 | * |
| 95 | * @param Task $task |
| 96 | * @param \core_kernel_classes_Resource|null $resource - placeholder resource to be linked with task. |
| 97 | * @throws |
| 98 | * @return \core_kernel_classes_Resource |
| 99 | */ |
| 100 | public function linkTask(Task $task, \core_kernel_classes_Resource $resource = null) |
| 101 | { |
| 102 | $taskResource = parent::linkTask($task, $resource); |
| 103 | $report = $task->getReport(); |
| 104 | if (!empty($report)) { |
| 105 | // serialize only two first report levels because sometimes serialized report is huge and it does not fit |
| 106 | // into `k_po` index of statemetns table. |
| 107 | $serializableReport = new Report($report->getType(), $report->getMessage(), $report->getData()); |
| 108 | foreach ($report as $subReport) { |
| 109 | $serializableSubReport = new Report( |
| 110 | $subReport->getType(), |
| 111 | $subReport->getMessage(), |
| 112 | $subReport->getData() |
| 113 | ); |
| 114 | $serializableReport->add($serializableSubReport); |
| 115 | } |
| 116 | $taskResource->setPropertyValue( |
| 117 | new \core_kernel_classes_Property(Task::PROPERTY_REPORT), |
| 118 | json_encode($serializableReport) |
| 119 | ); |
| 120 | } |
| 121 | return $taskResource; |
| 122 | } |
| 123 | } |