From 633cd11c5b129a9712dbc6e7867284fa7999cea5 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Dec 2022 10:44:54 +0000 Subject: move mod queueworker to /admin --- Zotlabs/Module/Admin/Queueworker.php | 106 ++++++++++++++++++++++++++++++ Zotlabs/Module/Queueworker.php | 123 ----------------------------------- Zotlabs/Widget/Admin.php | 1 + 3 files changed, 107 insertions(+), 123 deletions(-) create mode 100644 Zotlabs/Module/Admin/Queueworker.php delete mode 100644 Zotlabs/Module/Queueworker.php diff --git a/Zotlabs/Module/Admin/Queueworker.php b/Zotlabs/Module/Admin/Queueworker.php new file mode 100644 index 000000000..b7972b2db --- /dev/null +++ b/Zotlabs/Module/Admin/Queueworker.php @@ -0,0 +1,106 @@ + 3) ? $maxqueueworkers : 4; + set_config('queueworker', 'max_queueworkers', $maxqueueworkers); + + $maxworkerage = intval($_POST['queueworker_max_age']); + $maxworkerage = ($maxworkerage >= 120) ? $maxworkerage : 300; + set_config('queueworker', 'queueworker_max_age', $maxworkerage); + + $queueworkersleep = intval($_POST['queue_worker_sleep']); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + + goaway(z_root() . '/admin/queueworker'); + } + + function get() { + + $content = "

Queue Status

\n"; + + $r = q('select count(*) as total from workerq'); + + $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; + + $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); + + $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; + + $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); + + if ($r) { + $content .= "

Work items

"; + foreach($r as $rr) { + $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; + } + } + + $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); + $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; + + $sc = ''; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_maxworkers', + t('Max queueworker threads'), + $maxqueueworkers, + t('Minimum 4, default 4') + ] + ]); + + $workermaxage = get_config('queueworker', 'queueworker_max_age'); + $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_max_age', + t('Assume workers dead after'), + $workermaxage, + t('Minimum 120, default 300 seconds') + ] + ]); + + $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queue_worker_sleep', + t('Pause before starting next task'), + $queueworkersleep, + t('Minimum 100, default 100 microseconds') + ] + ]); + + $tpl = get_markup_template('settings_addon.tpl'); + $content .= replace_macros($tpl, [ + '$action_url' => 'queueworker', + '$form_security_token' => get_form_security_token('queueworker'), + '$title' => t('Queueworker Settings'), + '$content' => $sc, + '$baseurl' => z_root(), + '$submit' => t('Save') + ] + ); + + return $content; + + } +} diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php deleted file mode 100644 index 440132881..000000000 --- a/Zotlabs/Module/Queueworker.php +++ /dev/null @@ -1,123 +0,0 @@ - 3) ? $maxqueueworkers : 4; - set_config('queueworker', 'max_queueworkers', $maxqueueworkers); - - $maxworkerage = intval($_POST['queueworker_max_age']); - $maxworkerage = ($maxworkerage >= 120) ? $maxworkerage : 300; - set_config('queueworker', 'queueworker_max_age', $maxworkerage); - - $queueworkersleep = intval($_POST['queue_worker_sleep']); - $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); - - goaway(z_root() . '/queueworker'); - } - - function get() { - - $content = "

ERROR: Page not found

"; - App::$error = 404; - - if (!local_channel()) { - return $content; - } - - if (!(is_site_admin())) { - return $content; - } - - load_config("queueworker"); - - $content = "

Queue Status

\n"; - - $r = q('select count(*) as total from workerq'); - - $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; - - $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); - - $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; - - $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); - - if ($r) { - $content .= "

Work items

"; - foreach($r as $rr) { - $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; - } - } - - $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); - $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; - - $sc = ''; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queueworker_maxworkers', - t('Max queueworker threads'), - $maxqueueworkers, - t('Minimum 4, default 4') - ] - ]); - - $workermaxage = get_config('queueworker', 'queueworker_max_age'); - $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queueworker_max_age', - t('Assume workers dead after'), - $workermaxage, - t('Minimum 120, default 300 seconds') - ] - ]); - - $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); - $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queue_worker_sleep', - t('Pause before starting next task'), - $queueworkersleep, - t('Minimum 100, default 100 microseconds') - ] - ]); - - $tpl = get_markup_template('settings_addon.tpl'); - $content .= replace_macros($tpl, [ - '$action_url' => 'queueworker', - '$form_security_token' => get_form_security_token('queueworker'), - '$title' => t('Queueworker Settings'), - '$content' => $sc, - '$baseurl' => z_root(), - '$submit' => t('Save') - ] - ); - - return $content; - - } -} diff --git a/Zotlabs/Widget/Admin.php b/Zotlabs/Widget/Admin.php index 0a7a6925f..aa88de36a 100644 --- a/Zotlabs/Widget/Admin.php +++ b/Zotlabs/Widget/Admin.php @@ -32,6 +32,7 @@ class Admin { 'addons' => array(z_root() . '/admin/addons/', t('Addons'), 'addons'), 'themes' => array(z_root() . '/admin/themes/', t('Themes'), 'themes'), 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'), + 'queueworker' => array(z_root() . '/admin/queueworker', t('Queueworker'), 'queueworker'), 'profs' => array(z_root() . '/admin/profs', t('Profile Fields'), 'profs'), 'dbsync' => array(z_root() . '/admin/dbsync/', t('DB updates'), 'dbsync') ]; -- cgit v1.2.3