Skip to content

Asynchronous student import for Google Classroom integration - #1133

Merged
zetter-rpf merged 6 commits into
mainfrom
async-import-3
Nov 30, 2026
Merged

zetter-rpf merged 6 commits into
mainfrom
async-import-3

Conversation

@zetter-rpf

@zetter-rpf zetter-rpf commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Status

Points for consideration:

  • Security - This uses the users token in as an argument for the job. I don't really like this approach as it shares the token in more places and the token itself might become invalid. However, there's not good alternatives given the Profile API. We are already using this pattern in the SchoolImportJob.

What's changed?

We currently create student accounts (in profile) and student roles and class memberships (in editor-api) for the Google Classroom integration.

The profile API accepts up to 200 students, however we've found that it can timeout and cause errors in profile for ~100 students.

This keeps the class creation synchronous, but moves the student creation to a batched async method.

I've added progress reporting to the batch job so that we might be able to show progress on the frontend.

Steps to perform after deploying to production

Switch the frontend to use the new async option.

Extract existing code to the rspec config.

The ensure isn't needed as exceptions from specs are rescued (it would only help if we expect errors in the `around` itself)
@cla-bot cla-bot Bot added the cla-signed label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Test coverage

94.18% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/46399426661

@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-async-impo-iftdzd November 24, 2026 13:57 Inactive
This is lower level behaviour needed for importing students
@zetter-rpf
zetter-rpf temporarily deployed to editor-api-p-async-impo-iftdzd November 24, 2026 14:01 Inactive
@zetter-rpf zetter-rpf changed the title Async import 3 Asynchronous students import for Google Classroom integration Nov 24, 2026
@zetter-rpf
zetter-rpf marked this pull request as ready for review November 24, 2026 14:14
@macroscopeapp

macroscopeapp Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The opt-in import adds background student creation and progress reporting while preserving synchronous imports. Human confirmation is needed that GoodJob storage and retention appropriately protect the student details and caller token now persisted as job arguments.

Needs human approval because:

  • approvability is in preview mode for this repository, so Macroscope does not approve PRs here

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

Currently profile can take more than 15s to create students.

I don't like using the users token in an async job- as well as creating a copy of it, it might expire before the job runs, but there's not really an alternative at the moment.
I want to avoid overloading profile. It might be possible to up this concurrency in the future as the code in editor shouldn't prevent it running in parallel.
Since this might take a minute or longer, I wanted to see if we could report
progress to the frontend so people can see that it's in progress and not got stuck.
@zetter-rpf
zetter-rpf temporarily deployed to editor-api-p-async-impo-iftdzd November 24, 2026 14:47 Inactive
@zetter-rpf zetter-rpf changed the title Asynchronous students import for Google Classroom integration Asynchronous student import for Google Classroom integration Nov 24, 2026

@cocomarine cocomarine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!
A question: there is no retry on the new CreateAndAssignStudentsJob so a failed group of students will be skipped and the bacth still shows as finished. Is this intentional so that we don't call create_school_students_sso for the failed ones again or something?

@zetter-rpf

Copy link
Copy Markdown
Contributor Author

this intentional so that we don't call create_school_students_sso for the failed ones again or something?

Not really - I think I had assumed we retry all jobs by default which looks like it's not the case. I'll add a retry in as it may mean we can recover from temporary network issues and the job should be able to run multiple times for the same effect.

@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-async-impo-2ormaq November 30, 2026 10:16 Inactive
This is to catch any temporary network errors.

I've chosen not to do a polynomial wait as a user is waiting for this to complete.

I'm not sure why we would want a raise here as we're already reporting an error to sentry.
@zetter-rpf
zetter-rpf temporarily deployed to editor-api-p-async-impo-2ormaq November 30, 2026 10:22 Inactive
@zetter-rpf
zetter-rpf merged commit 81ee253 into main Nov 30, 2026
10 checks passed
@zetter-rpf
zetter-rpf deleted the async-import-3 branch November 30, 2026 10:27

This branch was previously deployed

2 inactive (1 outdated) deployments
editor-api-p-async-impo-2ormaq — c5bfe6f5 Deployed Nov 30, 2026 by zetter-rpf
editor-api-p-async-impo-iftdzd — 20495c70 Deployed Nov 24, 2026 by zetter-rpf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants