Skip to content

Make sync enrollments and sync assignments async with Good_job gem and Added good_job gem dashboard permission control#391

Closed
gobears01 wants to merge 2 commits intoberkeley-cdss:mainfrom
cs169:main
Closed

Make sync enrollments and sync assignments async with Good_job gem and Added good_job gem dashboard permission control#391
gobears01 wants to merge 2 commits intoberkeley-cdss:mainfrom
cs169:main

Conversation

@gobears01
Copy link
Copy Markdown
Contributor

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.
Added permission control for good_job gem admin dashboard to work in production

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
Added good_job initializer
Fixed lograge controller scoping
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

  • Name of branch corresponds to story

gobears01 and others added 2 commits March 31, 2026 10:56
Mass approve/ reject functionality and UI changes for request table
PR reviewed and merged into Golden Repo. Thank you!
@gobears01 gobears01 closed this Apr 20, 2026
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