-
Notifications
You must be signed in to change notification settings - Fork 1
Automatic Error Handling
The enrollment module can automatically reprocess any errors it may have experienced during the automatic cron run. This is extremely important if the process runs in the early morning where no human should be awake to manage the errors.
Developers can inject their own errors and error handlers into the enrollment process, should they desire. Some applicable points would be custom provider preprocess
and postprocess
.
The current ues
error types are: course
, department
, section
, custom
.
-
course
errors will pull all the course information for a semester (enrollment too) -
department
errors will pull enrollment for a particular department in a particular semester -
section
errors will pull enrollment for a particular section for a particular course in a particular semester
All except custom
are provisioned a handler.
The first step in a defining a custom error would be to determined how that error is handled. A handler
is the first argument given to ues_error::custom
. A handler
is an object containing two fields: file
and function
.
-
file
is an optional field that specifies the path, minus$CFG->dirroot
, to the code to be included for error handling. -
function
is any function in PHP that is_callable. In PHP version >= 5.3, a string function name, array static methods on objects, or closures are all considered callable functions.
Here's an example using a closure.
// Define how this error will be handled
$handler = new stdClass;
$handler->function = function($enrollment, $params) {
// Do my work
extract($params);
$enrollment->process_enrollment($semester, $course, $section);
};
$params = array(
"semester" => $section->semester(),
"course" => $section->course(),
"section" => $section
);
ues_error::custom($handler, $params)->save();
Here's an example of handler that would be used in multiple places. Assume you are building a ues enrollment provider plugin that injects provisioning behavior to the enrollment process located in {MOODLE_ROOT}/enrol/ues/plugins/custom
.
In /enrol/ues/plugins/custom/errors.php
:
abstract class error_handlers {
public static function in_preprocess($enrol, $params) {
// Work in here
}
public static function in_postprocess($enrol, $params) {
// Some more work
}
}
In /enrol/ues/plugins/custom/provider.php
:
// Somewhere in preprocess, something failed
try {
// trying it out
} catch (Exception $e) {
$handler = new stdClass;
$handler->file = "/enrol/ues/plugins/custom/errors.php";
$handler->function = array("error_handlers", "in_preprocess");
ues_error::custom($handler, array($whatever, $you_were, $working_with))->save();
}
Errors defined in either manner are capable of being automatically re-run in next cron run. Errors that were successfully reprocessed by their corresponding handlers are popped out of the error queue.