2019-05-02 06:01:43 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2022-01-02 08:27:47 +01:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-02 06:01:43 +02:00
|
|
|
|
|
|
|
namespace Friendica\Module\Admin;
|
|
|
|
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2020-01-23 05:14:14 +01:00
|
|
|
use Friendica\Module\BaseAdmin;
|
2019-05-02 06:01:43 +02:00
|
|
|
use Friendica\Util\Arrays;
|
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
|
|
|
|
/**
|
2020-01-19 07:05:23 +01:00
|
|
|
* Admin Inspect Queue Page
|
2019-05-02 06:01:43 +02:00
|
|
|
*
|
|
|
|
* Generates a page for the admin to have a look into the current queue of
|
|
|
|
* worker jobs. Shown are the parameters for the job and its priority.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-01-23 05:14:14 +01:00
|
|
|
class Queue extends BaseAdmin
|
2019-05-02 06:01:43 +02:00
|
|
|
{
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function content(array $request = []): string
|
2019-05-02 06:01:43 +02:00
|
|
|
{
|
2021-11-14 20:46:25 +01:00
|
|
|
parent::content();
|
2019-05-02 06:01:43 +02:00
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
$status = $this->parameters['status'] ?? '';
|
2019-05-02 06:01:43 +02:00
|
|
|
|
|
|
|
// get jobs from the workerqueue table
|
2020-09-08 16:38:35 +02:00
|
|
|
if ($status == 'deferred') {
|
2019-08-12 07:30:33 +02:00
|
|
|
$condition = ["NOT `done` AND `retrial` > ?", 0];
|
2020-01-18 20:52:34 +01:00
|
|
|
$sub_title = DI::l10n()->t('Inspect Deferred Worker Queue');
|
|
|
|
$info = DI::l10n()->t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
|
2019-05-02 06:01:43 +02:00
|
|
|
} else {
|
2019-08-12 07:30:33 +02:00
|
|
|
$condition = ["NOT `done` AND `retrial` = ?", 0];
|
2020-01-18 20:52:34 +01:00
|
|
|
$sub_title = DI::l10n()->t('Inspect Worker Queue');
|
|
|
|
$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.');
|
2019-05-02 06:01:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 16:20:02 +02:00
|
|
|
// @TODO Move to Model\WorkerQueue::getEntries()
|
2021-05-02 09:42:09 +02:00
|
|
|
$entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority', 'command'], $condition, ['limit' => 999, 'order' => ['created']]);
|
2019-05-02 06:01:43 +02:00
|
|
|
|
|
|
|
$r = [];
|
|
|
|
while ($entry = DBA::fetch($entries)) {
|
|
|
|
// fix GH-5469. ref: src/Core/Worker.php:217
|
|
|
|
$entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
|
|
|
|
$entry['created'] = DateTimeFormat::local($entry['created']);
|
|
|
|
$r[] = $entry;
|
|
|
|
}
|
|
|
|
DBA::close($entries);
|
|
|
|
|
|
|
|
$t = Renderer::getMarkupTemplate('admin/queue.tpl');
|
|
|
|
return Renderer::replaceMacros($t, [
|
2020-01-18 20:52:34 +01:00
|
|
|
'$title' => DI::l10n()->t('Administration'),
|
2019-05-02 06:01:43 +02:00
|
|
|
'$page' => $sub_title,
|
|
|
|
'$count' => count($r),
|
2020-01-18 20:52:34 +01:00
|
|
|
'$id_header' => DI::l10n()->t('ID'),
|
2021-05-02 09:42:09 +02:00
|
|
|
'$command_header' => DI::l10n()->t('Command'),
|
2020-01-18 20:52:34 +01:00
|
|
|
'$param_header' => DI::l10n()->t('Job Parameters'),
|
|
|
|
'$created_header' => DI::l10n()->t('Created'),
|
|
|
|
'$prio_header' => DI::l10n()->t('Priority'),
|
2019-05-02 06:01:43 +02:00
|
|
|
'$info' => $info,
|
|
|
|
'$entries' => $r,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|