aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-09-09 02:23:12 +0300
committerValentin Popov <info@valentineus.link>2018-09-09 02:23:12 +0300
commit2194bc4a019fcc1de191c76ab8a905b04b029292 (patch)
treed44b5c17dbd2e6e3d51c6eb40aa1ed080c26dd5d /classes
parent5884a58f544300f6674dc5bdcadfc16e8109749e (diff)
downloadlocal_webhooks-2194bc4a019fcc1de191c76ab8a905b04b029292.tar.xz
local_webhooks-2194bc4a019fcc1de191c76ab8a905b04b029292.zip
Refactoring the event handler
Event processing is asynchronous. For asynchronous processing, events are added to the job queue. Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'classes')
-rw-r--r--classes/event_observer.php (renamed from classes/handler.php)33
1 files changed, 13 insertions, 20 deletions
diff --git a/classes/handler.php b/classes/event_observer.php
index 3bc69cf..9ab4a35 100644
--- a/classes/handler.php
+++ b/classes/event_observer.php
@@ -15,41 +15,34 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * The event handler.
+ * Handlers of observers for events.
*
- * @package local_webhooks
- * @copyright 2017 "Valentin Popov" <info@valentineus.link>
+ * @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package local_webhooks
*/
namespace local_webhooks;
-defined("MOODLE_INTERNAL") || die();
-
-require_once(__DIR__ . "/../lib.php");
+defined( "MOODLE_INTERNAL" ) || die();
/**
* Defines event handlers.
*
- * @copyright 2017 "Valentin Popov" <info@valentineus.link>
+ * @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package local_webhooks
*/
-class handler {
+class event_observer {
/**
- * External handler.
+ * Handler of all the events.
+ * Each event is put into the job queue.
*
* @param object $event
*/
- public static function events($event) {
- /* Gets the information about the event */
- $data = $event->get_data();
-
- /* Gets a list of involved services */
- if (!empty($records = local_webhooks_get_list_records_by_event($data["eventname"]))) {
- foreach ($records as $record) {
- /* Sends an alert */
- local_webhooks_send_request($data, $record);
- }
- }
+ public static function observe_all( $event ) {
+ $task = new \local_webhooks\task\process_events_task();
+ $task->set_custom_data( $event->get_data() );
+ \core\task\manager::queue_adhoc_task( $task );
}
} \ No newline at end of file