Skip to content

Convert calsync observers to async adhoc tasks#3221

Open
patmr7 wants to merge 1 commit into
MOODLE_502_STABLEfrom
wip-130498-m502
Open

Convert calsync observers to async adhoc tasks#3221
patmr7 wants to merge 1 commit into
MOODLE_502_STABLEfrom
wip-130498-m502

Conversation

@patmr7

@patmr7 patmr7 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@patmr7 patmr7 force-pushed the wip-130498-m502 branch from 8d11848 to ff41a86 Compare June 12, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants