Skip to content

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

Open
gobears01 wants to merge 89 commits intoberkeley-cdss:mainfrom
cs169:gem-dashboards
Open

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

Conversation

@gobears01
Copy link
Copy Markdown
Contributor

@gobears01 gobears01 commented Apr 20, 2026

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

noahnizamian and others added 23 commits February 20, 2026 20:40
- Implemented user_to_courses_controller.rb with role-based authorization
- PATCH endpoint to toggle allow_extended_requests on enrollments
- Authorization: only teachers can toggle
- Uses lms_id FK pattern from LMS credentials refactoring
- Added teacher? method to UserToCourse model for role checking
- Complete spec with 7 test scenarios (instructor, student, missing resources)
- All tests passing: 365 examples, 0 failures, 80.88% coverage
Mass approve/ reject functionality and UI changes for request table
PR reviewed and merged into Golden Repo. Thank you!
Adjust DataTables data-priority values so only Actions, Assignment,
and Name columns remain visible on small screens. Bulk action buttons
are also hidden on mobile via Bootstrap responsive utility classes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gobears01 gobears01 changed the title Added good_job gem dashboard permission control Make sync enrollments and sync assignments async with Good_job gem and Added good_job gem dashboard permission control Apr 20, 2026
@gobears01
Copy link
Copy Markdown
Contributor Author

For your convenience, the heroku deployment is at: https://sp26-02-flextensions-45eafe44bb33.herokuapp.com/courses

gobears01 and others added 30 commits April 29, 2026 23:04
Late days column
Added one minor logic fix, resolved merge conflict due to UI change. All tests are passing
Enable/ Disable assignments

update_all method fixed. Skip rubocop validations
… not being one(no canvas association) => Fail after 1s
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.

6 participants