1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
class Queueworker extends Controller {
function init() {
}
function post() {
if ((!local_channel()) || (!is_site_admin())) {
goaway(z_root() . '/queueworker');
}
check_form_security_token('form_security_token', 'queueworker');
$maxqueueworkers = intval($_POST['queueworker_maxworkers']);
$maxqueueworkers = ($maxqueueworkers > 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 = "<H1>ERROR: Page not found</H1>";
App::$error = 404;
if (!local_channel()) {
return $content;
}
if (!(is_site_admin())) {
return $content;
}
load_config("queueworker");
$content = "<H1>Queue Status</H1>\n";
$r = q('select count(*) as total from workerq');
$content .= "<H4>There are " . $r[0]['total'] . " queue items to be processed.</H4>";
$r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null");
$content .= "<H4>Active workers: " . $r[0]['qworkers'] . "</H4>";
$r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd");
if ($r) {
$content .= "<H4>Work items</H4>";
foreach($r as $rr) {
$content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '<br>';
}
}
$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;
}
}
|