3 * @copyright Copyright (C) 2010-2023, the Friendica project
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 protected function content(array $request = []): string
45 $status = $this->parameters['status'] ?? '';
47 // get jobs from the workerqueue table
48 if ($status == 'deferred') {
49 $condition = ["NOT `done` AND `retrial` > ?", 0];
50 $sub_title = DI::l10n()->t('Inspect Deferred Worker Queue');
51 $info = DI::l10n()->t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
53 $condition = ["NOT `done` AND `retrial` = ?", 0];
54 $sub_title = DI::l10n()->t('Inspect Worker Queue');
55 $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.');
58 // @TODO Move to Model\WorkerQueue::getEntries()
59 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority', 'command'], $condition, ['limit' => 999, 'order' => ['created']]);
62 while ($entry = DBA::fetch($entries)) {
63 // fix GH-5469. ref: src/Core/Worker.php:217
64 $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
65 $entry['created'] = DateTimeFormat::local($entry['created']);
70 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
71 return Renderer::replaceMacros($t, [
72 '$title' => DI::l10n()->t('Administration'),
73 '$page' => $sub_title,
74 '$count' => count($r),
75 '$id_header' => DI::l10n()->t('ID'),
76 '$command_header' => DI::l10n()->t('Command'),
77 '$param_header' => DI::l10n()->t('Job Parameters'),
78 '$created_header' => DI::l10n()->t('Created'),
79 '$prio_header' => DI::l10n()->t('Priority'),