Adding a Proctor to Run Timed Quizzes
Let’s learn why it's important to schedule our quizzes and add a boundary API to our project.
Scheduling quizzes
To be useful in a classroom setting, Mastery should be able to schedule quizzes. Here’s the step by step flow for the major actors working with Mastery:
-
A teacher schedules a quiz.
-
At the quiz’s scheduled starting time, the proctor makes that quiz available in the quiz manager.
-
A student takes a quiz.
-
At the scheduled end time, the proctor automatically stops all student processes for that quiz and removes the quiz from the manager.
This is exactly the kind of machinery that defines the worker layer. It’s not lifecycle code because it lives outside of the configured lifecycle policies in our GenServers. It goes beyond simple boundary code because it will stop GenServer
processes. This is the domain of the worker layer.
We’ll implement it with a GenServer
and a boundary API. Let’s look at scheduling a quiz first. We’ll write an API function in Mastery that will call the API function in our as-yet-unwritten boundary GenServer
module.
Establish the boundary API
Let’s work from the outside in. Sometimes, working in this direction gives us an idea of what our API will look like before we dive into the details. The boundary layer will need a complex API to schedule a quiz so it will be available to users. We will start with the usual aliases in /lib/mastery.ex
:
Get hands-on with 1400+ tech skills courses.