friendica/src/Module/Admin/Queue.php

68 lines
2.1 KiB
PHP
Raw Normal View History

2019-05-02 00:01:43 -04:00
<?php
namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
2020-01-22 23:14:14 -05:00
use Friendica\Module\BaseAdmin;
2019-05-02 00:01:43 -04:00
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
/**
2020-01-19 01:05:23 -05:00
* Admin Inspect Queue Page
2019-05-02 00:01:43 -04: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-22 23:14:14 -05:00
class Queue extends BaseAdmin
2019-05-02 00:01:43 -04:00
{
public static function content(array $parameters = [])
2019-05-02 00:01:43 -04:00
{
2019-11-05 15:22:54 -05:00
parent::content($parameters);
2019-05-02 00:01:43 -04:00
$a = DI::app();
2019-05-02 00:01:43 -04:00
// @TODO: Replace with parameter from router
$deferred = $a->argc > 2 && $a->argv[2] == 'deferred';
// get jobs from the workerqueue table
if ($deferred) {
$condition = ["NOT `done` AND `retrial` > ?", 0];
$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 00:01:43 -04:00
} else {
$condition = ["NOT `done` AND `retrial` = ?", 0];
$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 00:01:43 -04:00
}
// @TODO Move to Model\WorkerQueue::getEntries()
$entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
2019-05-02 00:01:43 -04: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, [
'$title' => DI::l10n()->t('Administration'),
2019-05-02 00:01:43 -04:00
'$page' => $sub_title,
'$count' => count($r),
'$id_header' => DI::l10n()->t('ID'),
'$param_header' => DI::l10n()->t('Job Parameters'),
'$created_header' => DI::l10n()->t('Created'),
'$prio_header' => DI::l10n()->t('Priority'),
2019-05-02 00:01:43 -04:00
'$info' => $info,
'$entries' => $r,
]);
}
}