Repository navigation
Exam: record exam-result events in a transactional outbox - #31
Merged
Merged
Conversation
When an attempt's result becomes final (fully auto-graded on submit, or when the last essay is graded), an "exam.result_ready" event is written to outbox_events in the same transaction as the grade. OutboxRelay publishes pending rows in the background so the student can be e-mailed. - Off by default (APP_NOTIFY_EXAM_RESULTS=false): no outbox beans, no relay, resultReady() is a no-op. Existing deployments behave as before. - Publishers: "log" (local development, default) or "pubsub" (Google Cloud Pub/Sub over REST, authenticated with the VM's service account through the metadata server; no key file). - One event per attempt (unique event_type + aggregate_id); later re-grades do not send it again. Rows are locked with SKIP LOCKED so several instances can run the relay. Failed publishes are retried up to app.outbox.max-attempts. - The score is only included when the exam shows results to students. - V5 migration adds the outbox_events table. Frontend: the backend address Nginx proxies /api and /ws to is now BACKEND_UPSTREAM (default backend:8080, unchanged for Docker Compose), so the same image also works on Cloud Run where both containers share localhost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When an exam attempt's result becomes final, the backend records an
exam.result_readyevent so the student can be e-mailed. "Final" means fully auto-graded on submit, or the last essay graded by the teacher.The event is written to a new
outbox_eventstable in the same transaction as the grade. A committed grade therefore always has its event, and a rolled-back grade never does.OutboxRelaypublishes pending rows in the background.Details
APP_NOTIFY_EXAM_RESULTS=false). No outbox beans and no relay are created, andresultReady()is a no-op. Existing deployments behave exactly as before.log: for local development; the default when enabled.pubsub: Google Cloud Pub/Sub over REST. It authenticates with the VM's service account through the metadata server, so no key file is needed.event_type+aggregate_id). Re-grading an attempt does not send it again.SKIP LOCKED. Failed publishes are retried up toapp.outbox.max-attempts, and the last error is kept on the row.show_result).V5__outbox_events.sqladds the table./apiand/wsare now proxied toBACKEND_UPSTREAM. The default isbackend:8080, unchanged for Docker Compose. The same image also works on Cloud Run, where both containers share127.0.0.1.New settings
APP_NOTIFY_EXAM_RESULTSfalseAPP_OUTBOX_PUBLISHERloglogorpubsubAPP_OUTBOX_PUBSUB_TOPICprojects/<project>/topics/<topic>APP_OUTBOX_RELAY_INTERVAL_MS5000Testing
./mvnw clean testagainst PostgreSQL 16 and Redis 7: 66 tests, 0 failures. This includes new tests forOutboxRelay,PubSubRestPublisher,ExamResultEvents, and theExamRunnerServicehooks.nginx -tpasses withBACKEND_UPSTREAM=backend:8080and127.0.0.1:8080.Deploy note
Back up the database first. V5 creates an empty table on backend start. With the defaults, nothing else changes.