microsoft / o365-moodle

Office 365 and Azure Active Directory plugins for Moodle
GNU General Public License v3.0
184 stars 138 forks source link

Sync Moodle Courses to Teams Error - \local_o365\task\coursesync #2627

Closed diasalvesj closed 3 days ago

diasalvesj commented 3 months ago

I'm using Moodle in version Moodle 4.2.9+ (Build: 20240823) and integrating it with Microsoft 365. It turns out that since Sunday the task "\local_o365\task\coursesync" "stopped" working... The last time it ran was Sunday, August 25th and since then it has always been ASAP and does not connect or synchronize the new Moodle courses in MS Teams...

Before, the entire synchronization process was happening, even though some errors were identified (attachment).

I have some Moodle courses that are without teachers, therefore without owners, but this issue has never been a problem. I've also updated the secret and reviewed the permissions and consent, but everything is ok too.

Today my volume of Moodle courses is high...Has anyone experienced this demand or issue?

Screenshot_2 Screenshot_3 local_o365_task_coursesync-3395453.log

Tehnari commented 2 months ago

I can confirm the same errors with Moodle 4.4.2+ (Build: 20240823) | Version 2024042202.03 and Microsoft 365 Integration 2024042200. After upgrade to Moodle 4.4.2 from version 3.x receiving these errors. Changed apps on Microsoft 365 using PowerShell script, to exclude the human factor. Didn't work.

image image mld-asem-local_o365_task_coursesync-37637076.log

RayCoSector commented 2 months ago

Hello, we've noticed that after upgrading one customer who uses the course sync Team integration to local_o365 4.1.8 & the matching auth_oidc to 4.1.7 with Moodle 4.1.13.. the course sync process has gone from running within 1 hr has gone to taking 1 day and 10 hours ! image

I've then suggested to the customer that they streamline the amount of courses they are syncing, this has reduced it to 15 hrs to run image

I've added this to this ticket as our problem sound similar, the sync sits on ASAP whilst the sync is running for the 15 or so hours. @diasalvesj perhaps your issue is the database times out and now the sync never complete, try setting max_allowed_packets higher, by doing this

@weilai-irl has the latest version of the code 'fixed' a long standing issue which has now slowed down the sync ?

Regards, Ray Reid.

weilai-irl commented 2 months ago

Hi all,

@diasalvesj I see your latest runs finished with errors, does the task output give you details of the errors?

@Tehnari I don't think there are any issue on your site - all your task runs finish successfully. You see "ASAP" because the task is scheduled to run every minute, and each run would take longer than 1 minute to finish, so as soon as the last run finishes, it will start again in the next minute (assuming your Moodle cronjob runs every minute).

@RayCoSector Do you know from which local_o365 version was your site upgraded from? I don't recall any recent changes in the local_o365 plugin that would result in significant increase in time required to run the task.

I am aware that the task sucks at handling certain errors, such as when a group or user is deleted from Microsoft end directly, the task may retry 5 times regardless, and in case of a user, if the user is enrolled in multiple times, it will retry 5 times in each course. To make it worse, there's a 10 seconds delay between each retry. There is plan to improve this, and this is near the top of my list. Please keep tuned.

Regards, Lai

RayCoSector commented 2 months ago

Morning @weilai-irl just to answer your question, I've checked and noticed that this site moved from a really old 2022112805 version to the latest!

Regards, Ray.

diasalvesj commented 2 months ago

@weilai-irl Good morning, how are you? Here we noticed that...

The task output was showing:

"........ Could not get existing owners of group with ID 466a7fec-5028-4fdb-9355-b6a8bc856760. Reason: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Could not get existing members of group with ID 466a7fec-5028-4fdb-9355-b6a8bc856760. Reason: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ...... Adding 1 owner and 51 members to group with ID 466a7fec-5028-4fdb-9355-b6a8bc856760 ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Retry #1 ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Retry #1 ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Retry #1 ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Retry #1 ......... Error: Error in API call: Resource '466a7fec-5028-4fdb-9355-b6a8bc856760' does not exist or one of its queried reference-property objects are not present. ......... Finished adding owners and members to group."

And with that, we noticed that some hidden courses were entering the synchronization flow...

Our team here made a small hack in the code, and now we are only synchronizing active courses between Moodle and 365. What used to take 10-15 hours is now being done in 2 hours. At the institution here in Brazil, finishing the semester, we hid a batch of courses to start new ones for the current semester...

Here is the location and the file with the hack for you to check...

Adjusted location: o365/classes/feature/coursesync/main.php

main.zip

Tehnari commented 1 month ago

Hi all!. Sorry for late response.

@Tehnari I don't think there are any issue on your site - all your task runs finish successfully. You see "ASAP" because the task is scheduled to run every minute, and each run would take longer than 1 minute to finish, so as soon as the last run finishes, it will start again in the next minute (assuming your Moodle cronjob runs every minute).

Actually, not ASAP is the problem. Question is why teams are not created anymore. In log I see: Could not create class team from education group. Reason: Eroare în API call: Failed to execute Templates backend request CreateTeamFromGroupWithTemplateRequest. Request Url: https://teams.microsoft.com/fabric/emea/templates/api/groups/bc4d8489-d5bd-43af-a201-8fe3f8c50f64/team, Request Method: PUT, Response Status Code: BadRequest, Response Headers: Strict-Transport-Security: max-age=2592000 But from time to time I try to run manually this task, the same result. Till May, it worked well, and I didn't see an API problem in the logs.

weilai-irl commented 1 month ago

Hi all,

Please check out the latest release of the plugins which includes improvements in how the course sync task handles missing resource errors. This should hugely reduce the number of time it takes to run the task.

I'll keep this issue open for a new 2 weeks for feedback.

Regards, Lai