Convert calsync observers to async adhoc tasks#3221
Open
patmr7 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR moves Microsoft Graph calendar sync work out of synchronous calendar event observers and into an ad-hoc task, preventing long-running Graph calls from blocking web requests (notably for course events with large enrolments).
Changes:
- Added a new ad-hoc task (
synccalendarevent) to perform create/update/delete sync operations asynchronously. - Updated calendar event observers to enqueue the new ad-hoc task instead of calling Graph sync methods directly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
local/o365/classes/feature/calsync/task/synccalendarevent.php |
New ad-hoc task that executes the per-event Outlook sync actions. |
local/o365/classes/feature/calsync/observers.php |
Observers now queue synccalendarevent tasks for create/update/delete instead of running sync inline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * | ||
| * @return bool | ||
| */ | ||
| public function execute(): bool { |
Comment on lines
+36
to
+40
| * Custom data fields: | ||
| * - int eventid The ID of the Moodle calendar event. | ||
| * - string action One of 'create', 'update', or 'delete'. | ||
| * - array snapshot (delete only) JSON-encoded snapshot of the event record taken before deletion. | ||
| */ |
Comment on lines
+54
to
+73
| $data = $this->get_custom_data(); | ||
|
|
||
| $calsync = new \local_o365\feature\calsync\main(); | ||
|
|
||
| switch ($data->action) { | ||
| case 'create': | ||
| if (!$DB->record_exists('event', ['id' => $data->eventid])) { | ||
| return true; | ||
| } | ||
| $calsync->create_outlook_event_from_moodle_event($data->eventid); | ||
| break; | ||
|
|
||
| case 'update': | ||
| $calsync->update_outlook_event($data->eventid); | ||
| break; | ||
|
|
||
| case 'delete': | ||
| $calsync->delete_outlook_event($data->eventid, (object)$data->snapshot); | ||
| break; | ||
| } |
Synchronous Graph API calls in calendar event observers blocked web requests for minutes in courses with large enrolments. Replace direct sync calls with a new synccalendarevent adhoc task queued by each observer instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Synchronous Graph API calls in calendar event observers blocked web requests for minutes in courses with large enrolments. Replace direct sync calls with a new synccalendarevent adhoc task queued by each observer instead.