Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace tool_task\check;
18
 
19
use action_link;
20
use core\check\check;
21
use core\check\result;
22
use moodle_url;
23
 
24
/**
25
 * Ad hoc queue checks
26
 *
27
 * @package    tool_task
28
 * @copyright  2020 Brendan Heywood (brendan@catalyst-au.net)
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class adhocqueue extends check {
32
 
33
    /**
34
     * Return result
35
     * @return result
36
     */
37
    public function get_result(): result {
38
        global $DB, $CFG;
39
 
40
        $stats = $DB->get_record_sql('
41
            SELECT count(*) cnt,
42
                   MAX(? - nextruntime) age
43
              FROM {task_adhoc}', [time()]);
44
 
45
        $status = result::OK;
46
        $summary = get_string('adhocempty', 'tool_task');
47
        $details = '';
48
 
49
        if ($stats->cnt > 0) {
50
            // A large queue size by itself is not an issue, only when tasks
51
            // are not being processed in a timely fashion is it an issue.
52
            $status = result::INFO;
53
            $summary = get_string('adhocqueuesize', 'tool_task', $stats->cnt);
54
        }
55
 
56
        $max = $CFG->adhoctaskagewarn ?? 10 * MINSECS;
57
        if ($stats->age > $max) {
58
            $status = result::WARNING;
59
            $summary = get_string('adhocqueueold', 'tool_task', [
60
                'age' => format_time($stats->age),
61
                'max' => format_time($max),
62
            ]);
63
        }
64
 
65
        $max = $CFG->adhoctaskageerror ?? 4 * HOURSECS;
66
        if ($stats->age > $max) {
67
            $status = result::ERROR;
68
            $summary = get_string('adhocqueueold', 'tool_task', [
69
                'age' => format_time($stats->age),
70
                'max' => format_time($max),
71
            ]);
72
        }
73
 
74
        return new result($status, $summary, $details);
75
    }
76
 
77
    /**
78
     * Link to the Ad hoc tasks report
79
     *
80
     * @return action_link|null
81
     */
82
    public function get_action_link(): ?action_link {
83
        return new action_link(
84
            new moodle_url('/admin/tool/task/adhoctasks.php'),
85
            get_string('adhoctasks', 'tool_task'),
86
        );
87
    }
88
}