Browse Source

Move admin/queue to src/Module

- Add Module\Admin\Queue class
- Add route for admin/queue[/deferred]
- Add queue admin aside menu entry
- Remove obsolete templates/admin/queue.tpl from base and frio
- Move templates/admin/workerqueue.tpl to templates/admin/queue.tpl
- Remove admin_page_workerqueue and admin_page_workerqueue_post from mod/admin.php
- Update admin/summary.tpl with new queue admin paths
pull/7044/head
Hypolite Petovan 3 years ago
parent
commit
5a01c53781
  1. 57
      mod/admin.php
  2. 2
      src/App/Router.php
  3. 66
      src/Module/Admin/Queue.php
  4. 4
      src/Module/BaseAdminModule.php
  5. 12
      view/templates/admin/queue.tpl
  6. 2
      view/templates/admin/summary.tpl
  7. 21
      view/templates/admin/workerqueue.tpl
  8. 12
      view/theme/frio/templates/admin/queue.tpl
  9. 2
      view/theme/frio/templates/admin/summary.tpl
  10. 21
      view/theme/frio/templates/admin/workerqueue.tpl

57
mod/admin.php

@ -228,12 +228,6 @@ function admin_content(App $a)
case 'dbsync':
$o = admin_page_dbsync($a);
break;
case 'deferred':
$o = admin_page_workerqueue($a, true);
break;
case 'workerqueue':
$o = admin_page_workerqueue($a, false);
break;
case 'deleteitem':
$o = admin_page_deleteitem($a);
break;
@ -311,57 +305,6 @@ function admin_page_deleteitem_post(App $a)
return; // NOTREACHED
}
/**
* @brief Admin Inspect Worker Queue Page
*
* 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.
*
* The returned string holds the content of the page.
*
* @param App $a
* @param $deferred
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function admin_page_workerqueue(App $a, $deferred)
{
// get jobs from the workerqueue table
if ($deferred) {
$condition = ["NOT `done` AND `next_try` > ?", DateTimeFormat::utcNow()];
$sub_title = L10n::t('Inspect Deferred Worker Queue');
$info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
} else {
$condition = ["NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
$sub_title = L10n::t('Inspect Worker Queue');
$info = L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
}
$entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['order' => ['priority']]);
$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/workerqueue.tpl');
return Renderer::replaceMacros($t, [
'$title' => L10n::t('Administration'),
'$page' => $sub_title,
'$count' => count($r),
'$id_header' => L10n::t('ID'),
'$param_header' => L10n::t('Job Parameters'),
'$created_header' => L10n::t('Created'),
'$prio_header' => L10n::t('Priority'),
'$info' => $info,
'$entries' => $r,
]);
}
/**
* @brief Process send data from Admin Site Page
*

2
src/App/Router.php

@ -130,6 +130,8 @@ class Router
$collector->addRoute(['GET', 'POST'], '/features' , Module\Admin\Features::class);
$collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class);
$collector->addRoute(['GET'] , '/queue[/deferred]' , Module\Admin\Queue::class);
$collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class);
$collector->addRoute(['GET', 'POST'], '/tos' , Module\Admin\Tos::class);

66
src/Module/Admin/Queue.php

@ -0,0 +1,66 @@
<?php
namespace Friendica\Module\Admin;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Module\BaseAdminModule;
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
/**
* @brief Admin Inspect Queue Page
*
* 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
*/
class Queue extends BaseAdminModule
{
public static function content()
{
parent::content();
$a = self::getApp();
// @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 `next_try` > ?", DateTimeFormat::utcNow()];
$sub_title = L10n::t('Inspect Deferred Worker Queue');
$info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
} else {
$condition = ["NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
$sub_title = L10n::t('Inspect Worker Queue');
$info = L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
}
$entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['order' => ['priority']]);
$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' => L10n::t('Administration'),
'$page' => $sub_title,
'$count' => count($r),
'$id_header' => L10n::t('ID'),
'$param_header' => L10n::t('Job Parameters'),
'$created_header' => L10n::t('Created'),
'$prio_header' => L10n::t('Priority'),
'$info' => $info,
'$entries' => $r,
]);
}
}

4
src/Module/BaseAdminModule.php

@ -59,6 +59,10 @@ abstract class BaseAdminModule extends BaseModule
'features' => ['admin/features' , L10n::t('Additional features') , 'features'],
'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'],
]],
'database' => [L10n::t('Database'), [
'deferred' => ['admin/queue/deferred', L10n::t('Inspect Deferred Workers'), 'deferred'],
'workerqueue' => ['admin/queue' , L10n::t('Inspect worker Queue') , 'workerqueue'],
]],
'tools' => [L10n::t('Tools'), [
'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist') , 'contactblock'],
'blocklist' => ['admin/blocklist/server' , L10n::t('Server Blocklist') , 'blocklist'],

12
view/templates/admin/queue.tpl

@ -5,20 +5,16 @@
<table>
<tr>
<th>{{$id_header}}</th>
<th>{{$to_header}}</th>
<th>{{$url_header}}</th>
<th>{{$network_header}}</th>
<th>{{$param_header}}</th>
<th>{{$created_header}}</th>
<th>{{$last_header}}</th>
<th>{{$prio_header}}</th>
</tr>
{{foreach $entries as $e}}
<tr>
<td>{{$e.id}}</td>
<td>{{$e.name}}</td>
<td><a href="{{$e.nurl}}">{{$e.nurl}}</a></td>
<td>{{$e.network}}</td>
<td>{{$e.parameter}}</td>
<td>{{$e.created}}</td>
<td>{{$e.last}}</td>
<td>{{$e.priority}}</td>
</tr>
{{/foreach}}
</table>

2
view/templates/admin/summary.tpl

@ -11,7 +11,7 @@
<dl>
<dt>{{$queues.label}}</dt>
<dd><a href="{{$baseurl}}/admin/deferred">{{$queues.deferred}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></dd>
<dd><a href="{{$baseurl}}/admin/queue/deferred">{{$queues.deferred}}</a> - <a href="{{$baseurl}}/admin/queue">{{$queues.workerq}}</a></dd>
</dl>
<dl>
<dt>{{$pending.0}}</dt>

21
view/templates/admin/workerqueue.tpl

@ -1,21 +0,0 @@
<div id='adminpage'>
<h1>{{$title}} - {{$page}} ({{$count}})</h1>
<p>{{$info}}</p>
<table>
<tr>
<th>{{$id_header}}</th>
<th>{{$param_header}}</th>
<th>{{$created_header}}</th>
<th>{{$prio_header}}</th>
</tr>
{{foreach $entries as $e}}
<tr>
<td>{{$e.id}}</td>
<td>{{$e.parameter}}</td>
<td>{{$e.created}}</td>
<td>{{$e.priority}}</td>
</tr>
{{/foreach}}
</table>
</div>

12
view/theme/frio/templates/admin/queue.tpl

@ -5,20 +5,16 @@
<table class="table">
<tr>
<th>{{$id_header}}</th>
<th>{{$to_header}}</th>
<th>{{$url_header}}</th>
<th>{{$network_header}}</th>
<th>{{$param_header}}</th>
<th>{{$created_header}}</th>
<th>{{$last_header}}</th>
<th>{{$prio_header}}</th>
</tr>
{{foreach $entries as $e}}
<tr>
<td>{{$e.id}}</td>
<td>{{$e.name}}</td>
<td><a href="{{$e.nurl}}">{{$e.nurl}}</a></td>
<td>{{$e.network}}</td>
<td>{{$e.parameter}}</td>
<td>{{$e.created}}</td>
<td>{{$e.last}}</td>
<td>{{$e.priority}}</td>
</tr>
{{/foreach}}
</table>

2
view/theme/frio/templates/admin/summary.tpl

@ -14,7 +14,7 @@
{{* The work queues short statistic. *}}
<div id="admin-summary-queues" class="col-lg-12 col-md-12 col-sm-12 col-xs-12 admin-summary">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 admin-summary-label-name text-muted">{{$queues.label}}</div>
<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/deferred">{{$queues.deferred}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></div>
<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/queue/deferred">{{$queues.deferred}}</a> - <a href="{{$baseurl}}/admin/queue">{{$queues.workerq}}</a></div>
</div>
{{* Number of pending registrations. *}}

21
view/theme/frio/templates/admin/workerqueue.tpl

@ -1,21 +0,0 @@
<div id="adminpage">
<h1>{{$title}} - {{$page}} ({{$count}})</h1>
<p>{{$info}}</p>
<table class="table">
<tr>
<th>{{$id_header}}</th>
<th>{{$param_header}}</th>
<th>{{$created_header}}</th>
<th>{{$prio_header}}</th>
</tr>
{{foreach $entries as $e}}
<tr>
<td>{{$e.id}}</td>
<td>{{$e.parameter}}</td>
<td>{{$e.created}}</td>
<td>{{$e.priority}}</td>
</tr>
{{/foreach}}
</table>
</div>
Loading…
Cancel
Save