]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Queue.php
The federation statistics now contain all systems
[friendica.git] / src / Module / Admin / Queue.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
5 use Friendica\Core\L10n;
6 use Friendica\Core\Renderer;
7 use Friendica\Database\DBA;
8 use Friendica\DI;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Util\Arrays;
11 use Friendica\Util\DateTimeFormat;
12
13 /**
14  * @brief Admin Inspect Queue Page
15  *
16  * Generates a page for the admin to have a look into the current queue of
17  * worker jobs. Shown are the parameters for the job and its priority.
18  *
19  * @return string
20  */
21 class Queue extends BaseAdminModule
22 {
23         public static function content(array $parameters = [])
24         {
25                 parent::content($parameters);
26
27                 $a = DI::app();
28
29                 // @TODO: Replace with parameter from router
30                 $deferred = $a->argc > 2 && $a->argv[2] == 'deferred';
31
32                 // get jobs from the workerqueue table
33                 if ($deferred) {
34                         $condition = ["NOT `done` AND `retrial` > ?", 0];
35                         $sub_title = L10n::t('Inspect Deferred Worker Queue');
36                         $info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
37                 } else {
38                         $condition = ["NOT `done` AND `retrial` = ?", 0];
39                         $sub_title = L10n::t('Inspect Worker Queue');
40                         $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.');
41                 }
42
43                 // @TODO Move to Model\WorkerQueue::getEntries()
44                 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
45
46                 $r = [];
47                 while ($entry = DBA::fetch($entries)) {
48                         // fix GH-5469. ref: src/Core/Worker.php:217
49                         $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
50                         $entry['created'] = DateTimeFormat::local($entry['created']);
51                         $r[] = $entry;
52                 }
53                 DBA::close($entries);
54
55                 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
56                 return Renderer::replaceMacros($t, [
57                         '$title' => L10n::t('Administration'),
58                         '$page' => $sub_title,
59                         '$count' => count($r),
60                         '$id_header' => L10n::t('ID'),
61                         '$param_header' => L10n::t('Job Parameters'),
62                         '$created_header' => L10n::t('Created'),
63                         '$prio_header' => L10n::t('Priority'),
64                         '$info' => $info,
65                         '$entries' => $r,
66                 ]);
67         }
68 }