MDL-44432 use new task scheduler in new logging plugins

This commit is contained in:
Petr Škoda 2014-03-13 16:01:53 +08:00
parent 589eca14f2
commit a9336f676c
13 changed files with 166 additions and 62 deletions

View File

@ -134,16 +134,6 @@ class manager implements \core\log\manager {
$this->writers = null;
}
/**
* Execute cron actions.
*/
public function cron() {
$this->init();
foreach ($this->stores as $store) {
$store->cron();
}
}
/**
* Legacy add_to_log() redirection.
*

View File

@ -40,10 +40,4 @@ interface store {
* @return void
*/
public function dispose();
/**
* Execute cron actions.
* @return void
*/
public function cron();
}

View File

@ -209,9 +209,6 @@ class store implements \tool_log\log\writer, \core\log\sql_select_reader {
return $this->extdb->count_records_select($dbtable, $selectwhere, $params);
}
public function cron() {
}
/**
* Are the new events appearing in the reader?
*

View File

@ -91,17 +91,6 @@ class store implements \tool_log\log\store, \core\log\sql_select_reader {
}
}
public function cron() {
global $CFG, $DB;
// Delete old logs to save space (this might need a timer to slow it down...).
if (!empty($CFG->loglifetime)) { // Value in days.
$loglifetime = time(0) - ($CFG->loglifetime * 3600 * 24);
$DB->delete_records_select("log", "time < ?", array($loglifetime));
mtrace(" Deleted old log records");
}
}
/**
* Are the new events appearing in the reader?
*

View File

@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Legacy log reader.
*
* @package logstore_legacy
* @copyright 2014 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_legacy\task;
defined('MOODLE_INTERNAL') || die();
class cleanup_task extends \core\task\scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('taskcleanup', 'logstore_legacy');
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $CFG, $DB;
// Delete old logs to save space (this might need a timer to slow it down...).
if (!empty($CFG->loglifetime)) { // Value in days.
$loglifetime = time(0) - ($CFG->loglifetime * 3600 * 24);
$DB->delete_records_select("log", "time < ?", array($loglifetime));
mtrace(" Deleted old legacy log records");
}
}
}

View File

@ -15,23 +15,23 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Log tool API.
* Legacy log reader cron task.
*
* @package tool_log
* @copyright 2014 Petr Skoda {@link http://skodak.org/}
* @package logstore_legacy
* @copyright 2014 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Execute cron actions.
*/
function tool_log_cron() {
// Execute cron only if this log manager used.
$logmanager = get_log_manager();
if (get_class($logmanager) === 'tool_log\log\manager') {
/** @var \tool_log\log\manager $logmanager */
$logmanager->cron();
}
}
$tasks = array(
array(
'classname' => '\logstore_legacy\task\cleanup_task',
'blocking' => 0,
'minute' => '*',
'hour' => '5',
'day' => '*',
'dayofweek' => '*',
'month' => '*'
),
);

View File

@ -27,4 +27,5 @@ $string['legacy:read'] = 'Read logs';
$string['loglegacy'] = 'Log legacy data';
$string['loglegacy_help'] = 'This plugin records log data to the legacy log table (mdl_log). This functionality has been replaced by newer, richer and more efficient logging plugins, so you should only run this plugin if you have old custom reports that directly query the old log table. Writing to the legacy logs will increase load, so it is recommended that you disable this plugin for performance reasons when it is not needed.';
$string['pluginname'] = 'Legacy log';
$string['pluginname_desc'] = 'A log plugin that stores log entries in the legacy log table.';
$string['pluginname_desc'] = 'A log plugin that stores log entries in the legacy log table.';
$string['taskcleanup'] = 'Legacy log table cleanup';

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->version = 2014031300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014031200; // Requires this Moodle version.
$plugin->component = 'logstore_legacy'; // Full name of the plugin (used for diagnostics).

View File

@ -100,19 +100,6 @@ class store implements \tool_log\log\writer, \core\log\sql_internal_reader {
return 'logstore_standard_log';
}
public function cron() {
global $DB;
$loglifetime = $this->get_config('loglifetime', 0);
// NOTE: we should do this only once a day, new cron will deal with this.
if ($loglifetime > 0) {
$loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days.
$DB->delete_records_select("logstore_standard_log", "timecreated < ?", array($loglifetime));
mtrace(" Deleted old log records from standard store.");
}
}
/**
* Are the new events appearing in the reader?
*

View File

@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Standard log reader/writer.
*
* @package logstore_standard
* @copyright 2014 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_standard\task;
defined('MOODLE_INTERNAL') || die();
class cleanup_task extends \core\task\scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('taskcleanup', 'logstore_standard');
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $DB;
$loglifetime = (int)get_config('logstore_standard', 'loglifetime');
if ($loglifetime > 0) {
$loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days.
$DB->delete_records_select("logstore_standard_log", "timecreated < ?", array($loglifetime));
mtrace(" Deleted old log records from standard store.");
}
}
}

View File

@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Standard log reader/writer cron task.
*
* @package logstore_standard
* @copyright 2014 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => '\logstore_standard\task\cleanup_task',
'blocking' => 0,
'minute' => '*',
'hour' => '4',
'day' => '*',
'dayofweek' => '*',
'month' => '*'
),
);

View File

@ -26,3 +26,4 @@ $string['buffersize'] = 'Write buffer size';
$string['pluginname'] = 'Standard log';
$string['pluginname_desc'] = 'A log plugin stores log entries in a Moodle database table.';
$string['standard:read'] = 'Read logs';
$string['taskcleanup'] = 'Log table cleanup';

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014021100; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014012400; // Requires this Moodle version.
$plugin->version = 2014031300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014031200; // Requires this Moodle version.
$plugin->component = 'logstore_standard'; // Full name of the plugin (used for diagnostics).