3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Admin;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Arrays;
29 use Friendica\Util\DateTimeFormat;
32 * Admin Inspect Queue Page
34 * Generates a page for the admin to have a look into the current queue of
35 * worker jobs. Shown are the parameters for the job and its priority.
39 class Queue extends BaseAdmin
41 public static function content(array $parameters = [])
43 parent::content($parameters);
47 // @TODO: Replace with parameter from router
48 $deferred = $a->argc > 2 && $a->argv[2] == 'deferred';
50 // get jobs from the workerqueue table
52 $condition = ["NOT `done` AND `retrial` > ?", 0];
53 $sub_title = DI::l10n()->t('Inspect Deferred Worker Queue');
54 $info = DI::l10n()->t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
56 $condition = ["NOT `done` AND `retrial` = ?", 0];
57 $sub_title = DI::l10n()->t('Inspect Worker Queue');
58 $info = DI::l10n()->t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
61 // @TODO Move to Model\WorkerQueue::getEntries()
62 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
65 while ($entry = DBA::fetch($entries)) {
66 // fix GH-5469. ref: src/Core/Worker.php:217
67 $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
68 $entry['created'] = DateTimeFormat::local($entry['created']);
73 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
74 return Renderer::replaceMacros($t, [
75 '$title' => DI::l10n()->t('Administration'),
76 '$page' => $sub_title,
77 '$count' => count($r),
78 '$id_header' => DI::l10n()->t('ID'),
79 '$param_header' => DI::l10n()->t('Job Parameters'),
80 '$created_header' => DI::l10n()->t('Created'),
81 '$prio_header' => DI::l10n()->t('Priority'),