Make sync enrollments and sync assignments async with Good_job gem#379
Make sync enrollments and sync assignments async with Good_job gem#379gobears01 wants to merge 10 commits into
Conversation
Mass approve/ reject functionality and UI changes for request table PR reviewed and merged into Golden Repo. Thank you!
|
@gobears01 Can you merge in the upstream changes? I think for this PR we're pretty close, but there's some git conflicts. |
I have just resolved the conflicts and redeployed the latest version from this branch to heroku at: Please let me know if you see any issues. Thank you |
|
I'm closing this PR and and opened a new PR with permission control for good_job admin dashboard and resolved merge conflicts at #390 . Thank you! |
General Info
We need a framework to run async functions in the background (show status syncing). Async cast (sync enrollments/assignments should show status). We don’t want to wait 30/ 60s as per the current implementation
Changes
Previously, "Sync Enrollments" and "Sync Assignments" were synchronous: the HTTP request would block until all Canvas API calls completed, which could take 30–60 seconds and risk timing out. This PR makes both operations asynchronous using GoodJob, a PostgreSQL-backed Active Job backend.
Background job infrastructure:
Added GoodJob gem and ran its migration to create the good_jobs table in Postgres
Configured config.active_job.queue_adapter = :good_job in application.rb
Added a Procfile so Heroku runs a separate worker dyno alongside web
Added dotenv-rails gem to support loading .env locally
Async sync behavior:
Course#sync_assignments and Course#sync_users_from_canvas now call perform_later instead of running inline; the controller returns immediately after enqueuing
Added GET /courses/:id/sync_status endpoint that returns the last roster_synced_at / assignments_synced_at timestamps from CourseToLms
UI:
Both sync buttons now disable and show a "Syncing..." label + spinner immediately on click
The Stimulus controllers poll /sync_status every 1 second and reload the page with a banner notification once the job's timestamp changes, confirming completion
On timeout (60s) or error, an alert flash is shown and the button re-enabled
Testing
Added a full RSpec spec for SyncUsersFromCanvasJob covering: user upsert, enrollment creation, role-based removal, multi-role sync, return values/persistence, and non-array Canvas error responses
Rewrote the stale pending spec for SyncAllCourseAssignmentsJob#sync_assignment to test the instance method directly (create, update, unchanged)
Updated course_spec to verify sync_users_from_canvas enqueues the job rather than running inline
Added Cucumber scenarios for both sync buttons: visibility, disabled state, and spinner appearance after clicking
Set config.good_job.execution_mode = :external in test.rb to prevent GoodJob from executing jobs in-process during tests (which would cause the page to reload before Capybara could assert on the loading state)
Documentation
No documentation needed
Checklist